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:
Kai
2026-04-14 08:24:47 -03:00
committed by fiatjaf_
parent 8260e6245d
commit 6b8c242282
+8 -1
View File
@@ -476,7 +476,14 @@ export class AbstractRelay {
case 'AUTH': {
this.challenge = data[1] as string
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
}