From ea72623cde428319b4948ae051c38d77c57d4862 Mon Sep 17 00:00:00 2001 From: Patrick Mulligan Date: Thu, 2 Apr 2026 20:23:58 -0400 Subject: [PATCH] fix(nostr-client): reconnect indefinitely instead of giving up after 5 attempts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the relay reconnect logic gave up after 5 attempts (~31s). If the relay was down longer, the ATM permanently lost connectivity and couldn't fetch available balance — causing all bills to be rejected after the recent safety guard change. Now reconnects indefinitely with exponential backoff capped at 60s. Attempts reset on successful connection. Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/nostr-client/src/client.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/nostr-client/src/client.ts b/packages/nostr-client/src/client.ts index 6354f8b..58837df 100644 --- a/packages/nostr-client/src/client.ts +++ b/packages/nostr-client/src/client.ts @@ -54,7 +54,7 @@ export class NostrClient { this.config = { connectionTimeout: 10000, autoReconnect: true, - maxReconnectAttempts: 5, + maxReconnectAttempts: Infinity, ...config, } @@ -183,11 +183,16 @@ export class NostrClient { if (!connection) return if (connection.reconnectAttempts >= this.config.maxReconnectAttempts) { + console.warn(`[Nostr] Relay ${url}: max reconnect attempts reached`) return } connection.reconnectAttempts++ - const delay = Math.min(1000 * Math.pow(2, connection.reconnectAttempts), 30000) + // Exponential backoff: 2s, 4s, 8s, 16s, 32s, then cap at 60s + const delay = Math.min(1000 * Math.pow(2, connection.reconnectAttempts), 60000) + console.log( + `[Nostr] Relay ${url}: reconnecting in ${delay / 1000}s (attempt ${connection.reconnectAttempts})` + ) setTimeout(() => { this.connectToRelay(url)