fix(nostr): close SimplePool after publishing to prevent connection leak
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>
This commit is contained in:
parent
1368e15ea2
commit
f47ec6e86e
1 changed files with 17 additions and 13 deletions
|
|
@ -205,20 +205,24 @@ export class NostrPool {
|
||||||
const log = getLogger({ appName: keys.name })
|
const log = getLogger({ appName: keys.name })
|
||||||
this.log(`📤 Publishing Kind ${event.kind} event to ${relays.length} relay(s): ${relays.join(', ')}`)
|
this.log(`📤 Publishing Kind ${event.kind} event to ${relays.length} relay(s): ${relays.join(', ')}`)
|
||||||
const pool = new SimplePool()
|
const pool = new SimplePool()
|
||||||
await Promise.all(pool.publish(relays, signed).map(async p => {
|
try {
|
||||||
try {
|
await Promise.all(pool.publish(relays, signed).map(async p => {
|
||||||
await p
|
try {
|
||||||
sent = true
|
await p
|
||||||
} catch (e: any) {
|
sent = true
|
||||||
this.log(ERROR, `Failed to publish Kind ${event.kind} event:`, e.message || e)
|
} catch (e: any) {
|
||||||
log(e)
|
this.log(ERROR, `Failed to publish Kind ${event.kind} event:`, e.message || e)
|
||||||
|
log(e)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
if (!sent) {
|
||||||
|
this.log(ERROR, `Failed to send Kind ${event.kind} event to any relay`)
|
||||||
|
log("failed to send event")
|
||||||
|
} else {
|
||||||
|
this.log(`✅ Kind ${event.kind} event published successfully (id: ${signed.id.slice(0, 16)}...)`)
|
||||||
}
|
}
|
||||||
}))
|
} finally {
|
||||||
if (!sent) {
|
pool.close(relays)
|
||||||
this.log(ERROR, `Failed to send Kind ${event.kind} event to any relay`)
|
|
||||||
log("failed to send event")
|
|
||||||
} else {
|
|
||||||
this.log(`✅ Kind ${event.kind} event published successfully (id: ${signed.id.slice(0, 16)}...)`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue