Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensureRelay reconnect #333

Merged
merged 1 commit into from
Dec 21, 2023
Merged

ensureRelay reconnect #333

merged 1 commit into from
Dec 21, 2023

Conversation

syusui-s
Copy link
Contributor

The current implementation of ensureRelay connects to relays for the first time only. The second invocation of ensureRelay doesn't try to reconnect the relay even if it is disconnected.

This PR fixes that. It will try to connect if relay is disconnected.

Detail

The current implementation tries to send messages even if the connection is closed.
It causes the following error when I call pool.subscribeMany([failedRelay], ...):

Uncaught (in promise) Error: sending on closed connection

let subscription = relay.subscribe(filters, {

If this PR is merged, the connection error exception will be raised in this try block and it will be handled correctly.

nostr-tools/pool.ts

Lines 97 to 104 in a9acdad

try {
relay = await this.ensureRelay(url, {
connectionTimeout: params.maxWait ? Math.max(params.maxWait * 0.8, params.maxWait - 1000) : undefined,
})
} catch (err) {
handleClose(i, (err as any)?.message || String(err))
return
}

@fiatjaf fiatjaf merged commit ef12a45 into nbd-wtf:master Dec 21, 2023
1 of 2 checks passed
@syusui-s syusui-s deleted the fix_ensurerelay branch December 22, 2023 01:39
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.

2 participants