Skip to content

Commit e45a998

Browse files
committed
pool: prevent edge case with undefined subcloser.
1 parent 0c2c2cd commit e45a998

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

abstract-pool.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import { Relay } from './relay.ts'
1616
export type SubCloser = { close: (reason?: string) => void }
1717

1818
export type AbstractPoolConstructorOptions = AbstractRelayConstructorOptions & {
19-
// automaticallyAuth takes a relay URL and should return null
20-
// in case that relay shouldn't be authenticated against
19+
// automaticallyAuth takes a relay URL and should return null in case that relay shouldn't be authenticated against
2120
// or a function to sign the AUTH event template otherwise (that function may still throw in case of failure)
2221
automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise<VerifiedEvent>)
2322
// onRelayConnectionFailure is called with the URL of a relay that failed the initial connection
@@ -269,10 +268,13 @@ export class AbstractSimplePool {
269268
filter: Filter,
270269
params: Pick<SubscribeManyParams, 'label' | 'id' | 'onevent' | 'onclose' | 'maxWait' | 'onauth'>,
271270
): SubCloser {
272-
const subcloser = this.subscribe(relays, filter, {
271+
let subcloser: SubCloser
272+
subcloser = this.subscribe(relays, filter, {
273273
...params,
274274
oneose() {
275-
subcloser.close('closed automatically on eose')
275+
const reason = 'closed automatically on eose'
276+
if (subcloser) subcloser.close(reason)
277+
else params.onclose?.(relays.map(_ => reason))
276278
},
277279
})
278280
return subcloser

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nostr/tools",
3-
"version": "2.23.0",
3+
"version": "2.23.1",
44
"exports": {
55
".": "./index.ts",
66
"./core": "./core.ts",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "module",
33
"name": "nostr-tools",
4-
"version": "2.23.0",
4+
"version": "2.23.1",
55
"description": "Tools for making a Nostr client.",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)