Skip to content

Commit 2c16e98

Browse files
fix: timeout cleanup
1 parent 98f4eb6 commit 2c16e98

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

client-src/socket.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ let maxRetries = 10;
2222
// eslint-disable-next-line import/no-mutable-exports
2323
export let client = null;
2424

25+
let timeout;
26+
2527
/**
2628
* @param {string} url
2729
* @param {{ [handler: string]: (data?: any, params?: any) => any }} handlers
@@ -33,6 +35,10 @@ const socket = function initSocket(url, handlers, reconnect) {
3335
client.onOpen(() => {
3436
retries = 0;
3537

38+
if (timeout) {
39+
clearTimeout(timeout);
40+
}
41+
3642
if (typeof reconnect !== "undefined") {
3743
maxRetries = reconnect;
3844
}
@@ -57,7 +63,7 @@ const socket = function initSocket(url, handlers, reconnect) {
5763

5864
log.info("Trying to reconnect...");
5965

60-
setTimeout(() => {
66+
timeout = setTimeout(() => {
6167
socket(url, handlers, reconnect);
6268
}, retryInMs);
6369
}

0 commit comments

Comments
 (0)