-
Notifications
You must be signed in to change notification settings - Fork 959
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Firefox Websocket Issues #1425
Comments
I believe the problem is in Phoenix Socket. When the connection is closed it's not checking if This thread explains it better than I can: https://stackoverflow.com/questions/10965720/should-websocket-onclose-be-triggered-by-user-navigation-or-refresh I'm not really sure but it seems that changing At least in my setup the bug I had was fixed with this change, I'm not sure on what situations the code on the function would be used... onConnClose(event) {
// add this check and stop everything because page was closed ???
if (event.wasClean) {
return;
}
if (this.hasLogger()) this.log("transport", "close", event);
this.triggerChanError();
clearInterval(this.heartbeatTimer);
if (!this.closeWasClean) {
this.reconnectTimer.scheduleTimeout();
}
this.stateChangeCallbacks.close.forEach(([, callback]) => callback(event));
} |
Thanks for the report! I use Firefox and I never ran into such issue before. Can you try running a stock Firefox with no extensions and see if the issue persists? To be honest, I am not sure if the change above will fix it. Today we already don’t reconnect if the close was clean and that may be the issue in your case - but it also seems to be the correct choice of behavior. |
Yes, the issue persists even in a private window without extensions. Here is a better trace of what's going on, traced inside bindChannel():
This issue is not contained just to the console, as my "fix" does decrease the time-to-interactive on firefox by a couple of seconds, making it almost as fast as chrome. It seems as if page A is dispatching this "EventHandlerNonNull" and somehow page B is listening to it... |
I forgot I had this too, first time I booted LiveBook. Also Linux/FFX87 (though I have observed the behaviour for a month or so so probably older versions too). |
Unfortunately I cannot reproduce this, so someone will need to explore and submit the appropriate fix. :( |
I have the same issue. Not related to extensions, as checked on clear stock FF too. |
How often do you see this happen @lucasavila00? I go days between but your logs suggest you see it a bit more often than that? |
The "reload forever" bug happens once or twice a day. The "view crashed" bug happens 95% of the times I refresh a page. |
You are our chosen savior then. :D |
I see other libraries had the same issue, too: socketio/socket.io#3639 Maybe their fix is good for Phoenix?
I'm happy to do whatever is needed to debug this :) |
Hmm, do you have a project you can share with that hit rate? Something you can confirm as being that reliably unreliable? So I can try from a "known broken" - I have what sounds like the exact same bug but it's way less repeatable. |
@lucasavila00 in your requests screenshots, there is a "frame". Is this frame from your app or is this the live reload frame? Can you please tell me the full path for those frame requests? Also, does this happen on first access or only when navigating between pages? |
@rktjmp It happens with The only change from the starting code is that I enabled debug in the websockets:
This frame is the live reload frame. I need no extra code or something to trigger the issue. (from now on everything I'll send is from that repository)
It never happens on first access, on a clean tab. It happens when navigating or refreshing via the URL bar. (I have to test what happens if the link is clicked inside the page, be it a live link, normal link, etc - I'm working now, will do it properly at night BRT) |
Oh, I was able to reproduce it by adding enableDebug() - it is just the view being terminate - but from what you are seeing there is a chance it can mess something up. Thanks for the steps! |
@lucasavila00 can you try vendoring this client and attempt to reproduce? We used to bind to You should be able to copy this to assets/js/phoenix.js and then change your import to Thanks! https://gist.github.com/chrismccord/55bd22a04040f81ac98556bca05decce |
@chrismccord The message saying the view crashed is still there, but this client does not send an extra request to the server, and it loads (time to interactive) just as fast as in Chrome. By "extra request" I mean: When I refreshed, the old client would send these 2 requests (which I assume was the reason of the slowdown):
And the new one sends:
|
@chrismccord FYI I have been using this vendored Phoenix version ever since you sent it, developing my app with it for ~4h daily, and I have not had any issues with it so far. Not once did it enter the refresh-forever-loop I had before. |
Let me chime in here too. I've had this exact problems for months, every single day, after every suspend and only in Firefox. I was 100% convinced it was some kind of Firefox issue for which I cannot provide a nice repro. Likewise, I've switched to @chrismccord gist above around a week ago and absolutely 0 problems. |
Some firefox users reported odd connection issues caused by an unload listener ref: phoenixframework/phoenix_live_view#1425
Some firefox users reported odd connection issues caused by an unload listener ref: phoenixframework/phoenix_live_view#1425
This indeed appears to be an obscure Firefox issues affecting only some users. I've gone ahead and shipped the |
Some firefox users reported odd connection issues caused by an unload listener ref: phoenixframework/phoenix_live_view#1425
Environment
Actual behavior
Sometimes, the websocket won't connect in Firefox.
When it happens, doing a page reload fixes it most of the times, but sometimes not.
Sometimes, I have to close the entire browser and open it again to make Phoenix and Firefox connect.
My project is a
mix phx.new --live
with themix phx.gen.auth
auth code, but I've had the same issues when I cloned and ran Livebook.I don't know a lot of what might be causing this issue, but I've at least found a pattern which might help fix it:
Usually Firefox won't connect in the first attempt, logging this error:
But it works when it tries again:
The pattern I found is that when I enable latency simulation:
And the latency simulation message appears in the console before any other message, it will work:

When the message is not the first, it crashes:

The trace of the crash:

When I test the same code on Chrome, I get the messages in this order, all the time, and it never crashes:

Removing the latency simulation and debug calls in the JS code don't change this pattern/observation.
It seems that firefox keeps a copy of the channel even after a reload.
somehow firefox remembers the old token (redacted to TOKEN_B) even after a reload. I was able to log the channels internal details and the liveview id has this same pattern where the crash is tried with the liveviewid that was used in the page before the reload.
If I keep reloading the page the same pattern repeats.
In chrome, it's always:
The text was updated successfully, but these errors were encountered: