From d09f7c5427046ef093839cde71694292ef59e341 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 27 Aug 2024 11:15:00 -0500 Subject: [PATCH] Fix websocket leaks (#1334) --- lib/nostr.js | 9 ++++++++- worker/nostr.js | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/nostr.js b/lib/nostr.js index fb70c96e..b61ae304 100644 --- a/lib/nostr.js +++ b/lib/nostr.js @@ -69,6 +69,9 @@ export class Relay { try { return await withTimeout(checkPromise, timeout) + } catch (err) { + this.close() + throw err } finally { clearInterval(interval) } @@ -187,7 +190,11 @@ export function nostrZapDetails (zap) { async function publishNostrEvent (signedEvent, relayUrl) { const timeout = 3000 const relay = await Relay.connect(relayUrl, { timeout }) - await relay.publish(signedEvent, { timeout }) + try { + await relay.publish(signedEvent, { timeout }) + } finally { + relay.close() + } } export async function crosspost (event, relays = DEFAULT_CROSSPOSTING_RELAYS) { diff --git a/worker/nostr.js b/worker/nostr.js index b8ff8128..a84a2851 100644 --- a/worker/nostr.js +++ b/worker/nostr.js @@ -54,7 +54,11 @@ export async function nip57 ({ data: { hash }, boss, lnd, models }) { relays.map(async r => { const timeout = 1000 const relay = await Relay.connect(r, { timeout }) - await relay.publish(e, { timeout }) + try { + await relay.publish(e, { timeout }) + } finally { + relay.close() + } }) ) } catch (e) {