Phoenix LiveView hangs on websocket connection on all browsers

I’ve just started noticing that my Phoenix Liveview app hangs for a long time every time it must re-open a websocket connection. The warning I get after a few seconds is: “Websocket is closed before the connection is established”

I don’t think I have made any change recently that would start triggering this behavior except I started building my app remotely when deploying (with fly deploy --remote-only) because I was having issues deploying from my new mac with its M1 chip. I don’t see why that would affect anything but it might still be valuable info.

  • I get this issue on Brave, Chrome and Safari (so all browsers I’m pretty sure)
  • I have tried moving from the cdg region to ams, to no avail
  • Happens on both Windows and MacOS

I know this issue comes up on forums from time to time but unfortunately, none of the possible resolutions has helped me.

The app is at https://nara.fly.dev

EDIT: I redeployed my app and the issue is gone. I’m thinking it was an unhealthy instance or some temporary fluke in the network.

It is worth noting that I don’t have any of these issues in dev. So it might be a problem with Fly.

Can you open up your browser network debug tab and see what you get for the websocket connection headers? Mine looks like this:

It sounds like the initial connection works fine for you, then it can’t reconnect? Is that what’s happening?

1 Like

Hi Kurt, thanks for taking a look. It turns out I deployed a small change a few minutes ago (I just changed some HTML), and now this issue is gone. I see the same headers you do now.

It used to hang on every refresh and now I cannot reproduce it at all.

Could it be some unhealthy instances in Europe?

Anyway, good news, I guess :smiley: Thanks again

Well that’s strange, but I’m glad it’s working. Let us know if you see it again?

1 Like

Interesting issue. I have a similar problem after the issue today. Looks like it’s happening when I access a a specific instance (or region → one in CDG, one in FRA).

For me it appears like that. Whenever I open a new page that mounts a LiveView it reloads several times (4-6 times) until the page is stable. When I navigate within the liveview or via a live_redirect to another live view it seems to work fine. But when I reload the whole page or just click on a non-live link it reloads several times. It never happened before for me like this.

One of my customers (Toronto) had this issue too last year too. And I assumed it was an issue with his Brave browser. But I am not using Brave at all. And I saw this issue today on Chrome and Safari…

Any ideas how to debug or fix that?

@mathiasn this sounds like the issue from here: LiveView app unavailable for 2+ minutes after deployment - #15 by kurt

We just shipped a fix for this, you shouldn’t see that failed websocket+reload loop as often, possibly never.