mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 08:38:50 +00:00
use exponential backoff for reconnections.
This commit is contained in:
5
relay.js
5
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.`
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user