mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
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.
This commit is contained in:
1 parent
425f772fcc
commit
a54d5db263
1 file changed
+29
-3
+29
-3
@@ -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);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user