Merge pull request #1119 from PR0M3TH3AN/fix-hydration-hang-1209416647514971888

Prevent watch history hydration hang by adding timeout to pool.list
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-07 09:56:27 -05:00
commit 7f8405d366
1 file changed
+29 -3
+29 -3
View File
@@ -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);
});
};
}