Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src.ts/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,21 @@ export class AbstractProvider implements Provider {
});

if (sub.listeners.length === 0) {
if (sub.started) { sub.subscriber.stop(); }
this.#subs.delete(sub.tag);
// Defer teardown to allow once-listeners (e.g. waitForTransaction)
// to re-subscribe before the underlying subscriber is stopped.
// Without this, socket-based providers (WebSocket) would
// eth_unsubscribe and immediately need to eth_subscribe again on
// every block during waitForTransaction, and depending on timing
// the re-subscription could be lost entirely, causing subsequent
// waitForTransaction calls to hang forever.
const tag = sub.tag;
this._setTimeout(() => {
const s = this.#subs.get(tag);
if (s && s.listeners.length === 0) {
if (s.started) { s.subscriber.stop(); }
this.#subs.delete(tag);
}
}, this.pollingInterval);
}

return (count > 0);
Expand Down