fix(nostr): clear relay publish timers to prevent leaks and unhandled rejections#39742
fix(nostr): clear relay publish timers to prevent leaks and unhandled rejections#39742Bortlesboat wants to merge 1 commit into
Conversation
… rejections publishProfileEvent() uses Promise.race with a setTimeout-based timeout promise per relay. When pool.publish() wins the race, the pending setTimeout fires later and rejects a promise nobody is listening to, causing an unhandled promise rejection in strict Node environments. Similarly, importProfileFromRelays() creates both an overall timeout timer and per-relay subscription cleanup timers that continue running even when all relays respond before the deadline. Store timer handles and clear them in finally blocks so timers are always cleaned up regardless of which side wins the race. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Greptile SummaryThis PR fixes two timer leak issues in the Nostr extension:
Both changes are minimal, non-functional, and preserve the existing safety nets (e.g., Confidence Score: 5/5
Last reviewed commit: 9de9afd |
|
Closing — no maintainer engagement after 12 days. Happy to reopen if there's interest. |
Summary
publishProfileEvent()usesPromise.racewith asetTimeout-based timeout per relay. Whenpool.publish()resolves first, the pending timer fires later and rejects a promise nobody is listening to, causing anunhandledRejectionevent in strict Node.js environments.importProfileFromRelays()creates both an overall timeout timer and per-relay subscription cleanup timers that continue running even when all relays respond before the deadline.This stores timer handles and clears them in
finallyblocks so timers are always cleaned up regardless of which side wins the race.Changes
nostr-profile.ts: TracksetTimeouthandle per relay,clearTimeoutinfinallynostr-profile-import.ts: Track overall + per-relay timers, clear all infinallyTest plan
npx vitest run extensions/nostr/src/)