Skip to content

Conversation

@peymor19
Copy link

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 longPollFallbackMs delay.

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 longPollFallbackMs to 5500 ms
image

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

Thanks for your consideration!

@matheus1lva
Copy link

Im seing exactly the same thing, in my case even some next requests are being aborted because of that!

@lcmen
Copy link

lcmen commented Jan 4, 2026

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?

@SteffenDE
Copy link
Contributor

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,

@SteffenDE
Copy link
Contributor

Once LiveView falls back to long polling, does it never return to WebSockets?

@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.

@lcmen
Copy link

lcmen commented Jan 10, 2026

Once LiveView falls back to long polling, does it never return to WebSockets?

@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 clarificatio @SteffenDE ! I wasn't aware that the goal was to actually keep using longpoll until user closes the browser (and session gets wiped out).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants