Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edge browser Websocket connection will be automatically closed after an idle time

I did a test about Websocket on new Window Edge browser.

It seems that the websocket connection on the Edge browser will be automatically closed after an idle time (no data transmission b/w 2 endpoints). The issue does not happens on chrome or firefox.

I just wonder: Is there any additional configuration when initializing the websocket connection on Edge browser to keep the connection opened?

I really dont' want to implement heartbeat mechanism because actually everything still works well on other browsers.

like image 354
Chiến Nghê Avatar asked Sep 28 '22 00:09

Chiến Nghê


1 Answers

This might not be the answer you want, but...

Most production environments for websocket apps run behind a Websocket Proxy (Apache, Nginx etc') that usually also acts as a load balancer.

These servers will also implement a 'timeout' mechanism that is needed to avoid half closed sockets (when only one side closed the connection and no data is transmitted, no error is raised and the file handle can be left open indefinitely).

For instance, Heroku enforces a 55 second timeout window.

This means you should probably set up a heartbeat anyway - even if your development app doesn't experience shutdowns.

If you're writing a server-side app and have control over the websocket, you should probably set up ping frames that won't cause an onmessage event to be raised (ping and pong frames have a different op code and aren't part of the regular message sequence).

Some websocket frameworks (such as Plezi on Ruby) will set up pinging automatically as a default option, but some servers / frameworks leave this up to you.

To summarize:

These disconnections WILL be the expected behavior (even a required behavior) for a production environment. Although it's also very likely to be an MS Edge issue, you will probably have to implement a heartbeat in both cases.

P.S.

The Websocket standard states that:

Servers MAY close the WebSocket connection whenever desired. Clients SHOULD NOT close the WebSocket connection arbitrarily.

Servers (and Websocket Proxies and load balancers) use this to establish their timeouts. It's the client's responsibility to reconnect.

MS Edge really shouldn't utilize a timeout, as this isn't the expected behavior according to the standard... although Edge might be doing it to make sure the connection is still open (by forcing the script to reconnect as a reaction to a server's arbitrary disconnection).

like image 109
Myst Avatar answered Oct 07 '22 19:10

Myst