phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

Always reconnect after connection closes

Open laurglia opened this issue 1 year ago • 1 comments

Phoenix creates a new WebSocket connection if the current one closes for some reason. However, for a new connection to be created, it is required that the following conditions hold:

  • The connection did not exit cleanly. This is needed to not make the socket reconnect after it is manually disconnected with Socket#disconnect.
  • The WebSocket exit code was not normal (something other than 1000).

In some cases, the connection can close with the 1000 code and still require reconnecting. For example, when turning the internet off for around 1 minute, and turning it back on, then the connection sometimes closes with code 1000.

You can test that behavior on my test site: http://34.219.19.64:5000/

Here is also a video of the issue reproduced by me: https://www.youtube.com/watch?v=j76SvA3kglQ

This commit removes the requirement for the condition that the connection has to close with code 1000 to make reconnections more reliable. I found that the condition was first added in November 2021 with no explanation on why it was needed in the first place: https://github.com/phoenixframework/phoenix/commit/470337db9162284b892202ce8f6018a153aa83fc

If there is a good reason why this condition is set in place, do let me know, but otherwise I would go ahead and remove it.

The new behavior can be tested on my second test site: http://34.219.19.64:5001/

Vide of the new behavior: https://www.youtube.com/watch?v=q06kPuTln9Q

laurglia avatar Aug 23 '22 16:08 laurglia