From a54d5db263932a9d45ea78463f4bd806af130d96 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 7 Jan 2026 14:46:35 +0000 Subject: [PATCH] Fix: Add timeout to pool.list shim to prevent hydration hanging When relays fail to connect or do not send EOSE, the legacy `pool.list` shim would hang indefinitely, blocking watch history hydration. This change adds a timeout (default 7000ms) to ensure it returns whatever events it has collected, preventing the UI from getting stuck. --- js/nostr/toolkit.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/js/nostr/toolkit.js b/js/nostr/toolkit.js index 78d449d2..f3314803 100644 --- a/js/nostr/toolkit.js +++ b/js/nostr/toolkit.js @@ -544,8 +544,18 @@ export function shimLegacySimplePoolMethods(pool) { } return new Promise((resolve) => { - if (!subscription || typeof subscription.on !== "function") { + let timer = null; + + const finish = () => { + if (timer) { + clearTimeout(timer); + timer = null; + } resolve(events); + }; + + if (!subscription || typeof subscription.on !== "function") { + finish(); return; } @@ -558,11 +568,27 @@ export function shimLegacySimplePoolMethods(pool) { } catch (error) { devLogger.warn("[nostr] Failed to unsubscribe after list EOSE.", error); } - resolve(events); + finish(); }); subscription.on("close", () => { - resolve(events); + finish(); }); + + // Prevent hanging indefinitely if relays fail to EOSE + const timeoutMs = + Number.isFinite(opts.timeout) && opts.timeout > 0 + ? opts.timeout + : 7000; + + timer = setTimeout(() => { + timer = null; + try { + subscription.unsub?.(); + } catch (error) { + // ignore + } + finish(); + }, timeoutMs); }); }; }