-
Notifications
You must be signed in to change notification settings - Fork 249
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
π Bug Report β Runtime APIs: Hibernating WebSockets remain open when leaving webpage #1187
Comments
We're investigating this. Are you able to verify that the browser is actually closing the connections? |
@kentonv I suspected that too, so I did the following:
The socket remains open on CF side. I'm not aware of any socket that can survive the machine shutting down, so I'm guessing it's closing them :) |
Thank you for the details! We've identified the issue. Really appreciate the detailed bug report! |
The fix has begun rolling out, but probably won't reach most places until tomorrow. The problem occurs when a client disconnects a WebSocket without sending a close message first, and the WebSocket was hibernated. For posterity, the actual bugfix: b529704 We've also added test coverage (not visible publicly, unfortunately), and are also making this class of bug into a compile-time error: capnproto/capnproto#1810 |
Thanks for the turnaround on this, deeply appreciate it! |
The fix is fully rolled out (as of ~8:00 UTC, several hours ago). Thanks @jevakallio for the amazing bug report, and @MellowYarker and @jasnell for debugging and fixing. |
Problem
We started observing the following strange behaviour some time yesterday.
state.acceptWebSocket(socket)
,WebSocket
APIwebSocketClose
callback is not executedstate.getWebSockets()
continues to return the connectionconnection.readyState
continues to report1
(OPEN)Minimal reproduction
Code: https://github.com/jevakallio/wrangler-raw/tree/hibernating-sockets-repro/src
Demo: https://jevakallio-wrangler-raw.partykit.dev/?room=objectname
Steps
The issue seems to be triggered inconsistently, but observed as follows
You can change the
room
search parameter to get a different durable object instance for testing, e.g. https://jevakallio-wrangler-raw.partykit.dev/?room=repro-anything-else-hereExpected
webSocketClose
message in the other tab.Actual
webSocketClose
message is sent only sporadicallyWorkaround
The client can work around this issue by calling
websocket.close()
manually when the page is unloaded:You can see the workaround in action by appending a
close
search parameter to the URL:https://jevakallio-wrangler-raw.partykit.dev/?room=objectname&close
Other information
This issue started occurring in a live application some time yesterday afternoon/evening UTC. We did not see this issue before.
Initially, we noticed this on one of our sample apps that's supposed to show live connections only:
https://multicursor-sketch.vercel.app/?partyhost=voronoi-party.genmon.partykit.dev
We can see from this demo that:
I deployed the same code without hibernation, and that works as expected:
https://multicursor-sketch.vercel.app/?partyhost=voronoi-party.jevakallio.partykit.dev
The text was updated successfully, but these errors were encountered: