Fix websocket leaks (#1334)

This commit is contained in:
ekzyis 2024-08-27 11:15:00 -05:00 committed by GitHub
parent ec6124ca62
commit d09f7c5427
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -69,6 +69,9 @@ export class Relay {
try { try {
return await withTimeout(checkPromise, timeout) return await withTimeout(checkPromise, timeout)
} catch (err) {
this.close()
throw err
} finally { } finally {
clearInterval(interval) clearInterval(interval)
} }
@ -187,7 +190,11 @@ export function nostrZapDetails (zap) {
async function publishNostrEvent (signedEvent, relayUrl) { async function publishNostrEvent (signedEvent, relayUrl) {
const timeout = 3000 const timeout = 3000
const relay = await Relay.connect(relayUrl, { timeout }) const relay = await Relay.connect(relayUrl, { timeout })
try {
await relay.publish(signedEvent, { timeout }) await relay.publish(signedEvent, { timeout })
} finally {
relay.close()
}
} }
export async function crosspost (event, relays = DEFAULT_CROSSPOSTING_RELAYS) { export async function crosspost (event, relays = DEFAULT_CROSSPOSTING_RELAYS) {

View File

@ -54,7 +54,11 @@ export async function nip57 ({ data: { hash }, boss, lnd, models }) {
relays.map(async r => { relays.map(async r => {
const timeout = 1000 const timeout = 1000
const relay = await Relay.connect(r, { timeout }) const relay = await Relay.connect(r, { timeout })
try {
await relay.publish(e, { timeout }) await relay.publish(e, { timeout })
} finally {
relay.close()
}
}) })
) )
} catch (e) { } catch (e) {