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)