Skip to content

fix(nostr): async error handling and SimplePool connection leak#892

Draft
PatMulligan wants to merge 3 commits intoshocknet:masterfrom
PatMulligan:fix/nostr-send-async
Draft

fix(nostr): async error handling and SimplePool connection leak#892
PatMulligan wants to merge 3 commits intoshocknet:masterfrom
PatMulligan:fix/nostr-send-async

Conversation

@PatMulligan
Copy link

Summary

  • NostrSend type was synchronous (void) but the implementation was async, causing fire-and-forget promises that silently swallowed errors
  • Updated type signature to Promise<void> and added await + error handling at all call sites
  • SimplePool was never closed after publishing events, leaking WebSocket connections over time — now properly closed after use

Test plan

  • Verify Nostr event publishing logs errors instead of silently failing
  • Monitor WebSocket connections over time — no more leaked SimplePool connections

PatMulligan and others added 3 commits March 1, 2026 17:25
The NostrSend type was incorrectly typed as returning void when it actually
returns Promise<void>. This caused async errors to be silently swallowed.

Changes:
- Update NostrSend type signature to return Promise<void>
- Make NostrSender._nostrSend default to async function
- Add .catch() error handling in NostrSender.Send() to log failures
- Add logging to track event publishing status

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update all NostrSend call sites to properly handle the async nature
of the function now that it returns Promise<void>.

Changes:
- handler.ts: Add async to sendResponse, await nostrSend calls
- debitManager.ts: Add logging for Kind 21002 response sending
- nostrMiddleware.ts: Update nostrSend signature
- tlvFilesStorageProcessor.ts: Update nostrSend signature
- webRTC/index.ts: Add async/await for nostrSend calls

This ensures Kind 21002 (ndebit) responses are properly sent to
wallet clients, fixing the "Debit request failed" issue in ShockWallet.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Each sendEvent() call created a new SimplePool() but never closed it,
causing relay WebSocket connections to accumulate indefinitely (~20/min).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shocknet-justin shocknet-justin requested a review from boufni95 March 1, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant