mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2026-10-05 14:38:23 +00:00
fix(nip42): catch SendingOnClosedConnection during automatic AUTH
Fixes #531. When automaticallyAuth is configured and a relay closes the connection between sending the AUTH challenge and the client sending the signed response, the SendingOnClosedConnection error was propagating as an unhandled promise rejection. This is a race condition that commonly occurs with relays that enforce WoT or whitelists - they accept the WebSocket, send an AUTH challenge, but close the connection before the client can respond. The fix catches the SendingOnClosedConnection error specifically in the AUTH case handler, preventing unhandled rejections while still propagating other errors.
This commit is contained in:
+8
-1
@@ -476,7 +476,14 @@ export class AbstractRelay {
|
|||||||
case 'AUTH': {
|
case 'AUTH': {
|
||||||
this.challenge = data[1] as string
|
this.challenge = data[1] as string
|
||||||
if (this.onauth) {
|
if (this.onauth) {
|
||||||
this.auth(this.onauth)
|
this.auth(this.onauth).catch(err => {
|
||||||
|
// If the connection closed before auth could be sent, just ignore it.
|
||||||
|
// This is a race condition when relays close connections quickly
|
||||||
|
// (e.g., WoT-enforced relays that reject unknown pubkeys).
|
||||||
|
if (!(err instanceof SendingOnClosedConnection)) {
|
||||||
|
throw err // re-throw other errors
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user