use exponential backoff for reconnections.

This commit is contained in:
fiatjaf
2021-12-12 11:39:43 -03:00
parent 02cacd4446
commit 22e895c7c2
2 changed files with 5 additions and 2 deletions

View File

@@ -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.`
)