Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Why does creation of a new websocket stall for up to a minute?

  • No replies
  • 1 has this problem
  • 4 views
more options

I made a websocket client that reconnects automatically after 1 second at WebSocket.onclose(). I do not have the server running, so that I can see what will happen if a client disconnects to network issues, going offline, etc. For the first ten or so connections, Firefox 72 behaves as expected, but then it starts stalling new websocket creations. Eventually the stall peaks at about 1 minute, but two connections are attempted before each stall.

I don't see how this is rational behavior. I don't want a user who disconnects from my server (e.g. leaves WiFi) to have to wait up to a minute to reconnect. Even a refresh or close tab and reopen will not get an immediate websocket connection attempt. The only way to get an immediate attempt is to close Firefox entirely and reopen.

I also don't understand the policy of websockets using an increasing timeout (up to a few minutes or more) for several reconnection attempts while in the OPEN state. Thankfully there is an obvious workaround which is to implement manual ping/pong with close on timeout.

I suppose I could make some HTTP requests to see if the server is up and then create a websocket but that seems just ugly.

On Chromium, the maximum timeout is only a few seconds and through the entire timeout Chromium is still making tcp SYN attempts several times per second.

Reproduce: - client.js: https://pastebin.com/NP7iWbEg - client.html: https://pastebin.com/BzxDP3EZ

1) Put client.js and client.html into a directory and open client.html in Firefox 72. 2) (optional) Do the same but with Chromium.

I made a websocket client that reconnects automatically after 1 second at WebSocket.onclose(). I do not have the server running, so that I can see what will happen if a client disconnects to network issues, going offline, etc. For the first ten or so connections, Firefox 72 behaves as expected, but then it starts stalling new websocket creations. Eventually the stall peaks at about 1 minute, but two connections are attempted before each stall. I don't see how this is rational behavior. I don't want a user who disconnects from my server (e.g. leaves WiFi) to have to wait up to a minute to reconnect. Even a refresh or close tab and reopen will not get an immediate websocket connection attempt. The only way to get an immediate attempt is to close Firefox entirely and reopen. I also don't understand the policy of websockets using an increasing timeout (up to a few minutes or more) for several reconnection attempts while in the OPEN state. Thankfully there is an obvious workaround which is to implement manual ping/pong with close on timeout. I suppose I could make some HTTP requests to see if the server is up and then create a websocket but that seems just ugly. On Chromium, the maximum timeout is only a few seconds and through the entire timeout Chromium is still making tcp SYN attempts several times per second. Reproduce: - client.js: https://pastebin.com/NP7iWbEg - client.html: https://pastebin.com/BzxDP3EZ 1) Put client.js and client.html into a directory and open client.html in Firefox 72. 2) (optional) Do the same but with Chromium.