Slowing reconnect websocket in Firefox. Why? How to overcome?

Hello, colleagues!

Implement the communication with server using WebSocket's.
The plan needs to be an automatic reconnect.
Do here such code:
"use strict";

let webSocket = undefined;
let timer = 0;

function Link (url) {
 startWebSocket function () {
 if (webSocket !== undefined) return;

 webSocket = new WebSocket(url);

 webSocket.onmessage = event => console.log(event);
 webSocket.onopen = () => { 
 if (timer === 0) return;
clearInterval(timer);
 timer = 0;
};
 webSocket.onclose = () => {
 webSocket = undefined;
 if (timer === 0) timer = setInterval(startWebSocket, 1000);
};
}

 function sendMessage (message) {
 if (webSocket === undefined) return;
webSocket.send(message);
}

 return {
 send: sendMessage,
 start startWebSocket
};
}

export default Link;


From the code all superfluous removed. There is still preprocessing the received messages and generate events to open/close/error/received message, but that's irrelevant.

There is a problem. In Firefox'E. After about 10 attempts of connect retry delay increases to 30 or more seconds. In Chrome this is not observed.

This is a bug or a feature?

How to defeat this behavior?

UPD: in comments described in detail: as in my opinion the code is running.
July 2nd 19 at 17:08
0 answer

Find more questions by tags Mozilla FirefoxJavaScript