From be3f146852eb482b07c0e9e153db66637a57381c Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Wed, 11 Nov 2020 18:56:34 -0600 Subject: [PATCH] fix: don't stack up reopeners --- packages/dapp-svelte-wallet/ui/src/websocket.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/dapp-svelte-wallet/ui/src/websocket.js b/packages/dapp-svelte-wallet/ui/src/websocket.js index 70ca2dce8a5..594e32fe873 100644 --- a/packages/dapp-svelte-wallet/ui/src/websocket.js +++ b/packages/dapp-svelte-wallet/ui/src/websocket.js @@ -20,9 +20,10 @@ export function makeWebSocket(path, { onOpen, onMessage, onClose }) { } const RECONNECT_BACKOFF_SECONDS = 3; + let reopenTimeout; function reopen() { console.log(`Reconnecting in ${RECONNECT_BACKOFF_SECONDS} seconds`); - setTimeout(openSocket, RECONNECT_BACKOFF_SECONDS * 1000); + reopenTimeout = setTimeout(openSocket, RECONNECT_BACKOFF_SECONDS * 1000); } let socket = null; @@ -31,6 +32,7 @@ export function makeWebSocket(path, { onOpen, onMessage, onClose }) { if (socket) { return; } + clearTimeout(reopenTimeout); socket = new WebSocket(`${wsurl}`); retryStrategy = reopen;