-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix immediate fallback to long poll when websocket connection is lost #6208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Peyton Morrison <[email protected]>
|
Im seing exactly the same thing, in my case even some next requests are being aborted because of that! |
|
I’m learning Phoenix, and I keep running into the same issue during development. When I leave a LiveView tab and then shut down the server, it sometimes falls back to long polling, assigns a fallback long-poll record in the session, and never goes back to WebSockets until I remove the session entry. Is this the expected behavior? Once LiveView falls back to long polling, does it never return to WebSockets? |
|
I'm don't think the expected behavior is to actually wait (AND RETRY) for the given amount. When the WebSocket connection explicitly fails, we try LongPoll immediately. We cannot know why the WebSocket connection failed, it might be a firewall blocking websockets and you wouldn't want to delay all connections unnecessarily. So currently, we only fall back when the websocket connection is stuck. If you don't want to fallback in development, do something like this: longPollFallbackMs: location.host.startsWith("localhost") ? null : 2500, |
@lcmen if WebSockets did work previously, Phoenix will retry WebSockets when you reload the page. Otherwise, Phoenix will retry as soon as the browser session storage is cleared, which usually happens when the last tab for your origin is closed. So if you visit the page later, WebSockets will be tried first again. |
Gotcha, thank you for |
|
@SteffenDE This happens a bit too often in my setup and I'd be interested in knowing if there is a "clean" way to force Liveview to retry WebSockets? Apart from programmatically deleting the item in SessionStorage and reloading the page, that is. If not I'd be happy to try to add such a feature. |
|
@westmark the following should work liveSocket.replaceTransport(WebSocket);How do you decide when to execute that though? |
|
@SteffenDE I was thinking at first to just display a message somewhere with an "Upgrade connection" button. My users are few and technical, so it should do fine. Later on I might try to upgrade on some reasonable interval. However, I guess I will run into trouble with users on company networks with strict WS policies, so maybe I'll have to take that into account as well. |
When a browser client loses its web socket connection to the server, I noticed that it immediately falls back to long poll without respecting the
longPollFallbackMsdelay.This causes all connected browser clients to fall back to long poll when restarting an Elixir server, instead of attempting to reconnect to a new web socket as expected.
I have added a failing test and a potential fix.
I am not sure that the implementation of the fix is the best so I would appreciate some insight on the issue before diving deeper into a better solution.
In this image you can see that I set the

longPollFallbackMsto 5500 msThis image shows the client immediately falling back to long poll instead of waiting the 5500ms for a web socket connection.

Thanks for your consideration!