From 22e895c7c217b35e338551f20cec2ac3ef4613ce Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 12 Dec 2021 11:39:43 -0300 Subject: [PATCH] use exponential backoff for reconnections. --- package.json | 2 +- relay.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 04ac75f..a4cf875 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nostr-tools", - "version": "0.8.0", + "version": "0.8.1", "description": "Tools for making a Nostr client.", "repository": { "type": "git", diff --git a/relay.js b/relay.js index cc35cc2..d7064db 100644 --- a/relay.js +++ b/relay.js @@ -46,7 +46,10 @@ export function relayConnect(url, onNotice) { ws.onclose = () => { resetOpenState() attemptNumber++ - nextAttemptSeconds += attemptNumber + nextAttemptSeconds += attemptNumber ** 3 + if (nextAttemptSeconds > 14400) { + nextAttemptSeconds = 14400 // 4 hours + } console.log( `relay ${url} connection closed. reconnecting in ${nextAttemptSeconds} seconds.` )