Skip to content
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

Call onclose when closing the connection in the checkinterval #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

johnstleger
Copy link

@johnstleger johnstleger commented Feb 2, 2022

Context
In Safari the Websocket does not call onclose when the socket is closed manually.

The problem
This means that if a connection is closed in the interval in Safari it doesn't try to reconnect. Users end up in a state where y-websocket states that they are connected. But they are disconnected and y-websocket doesn't try to reconnect... users lose their edits.

Reproduce
It's easy to reproduce. Switch from one wifi network to another (i.e. to your phone using tethering) and you'll see it disconnects silently and never reconnects.

Websocket does not call onclose when the socket is closed manually
@dmonad
Copy link
Member

dmonad commented Mar 21, 2022

I'm a bit confused. Does this happen when you manually close the connection (provider.disconnect()) or when switching between routers?

If I can't detect that a connection is closed, then this is probably a browser issue.

@TJackwood-Jasper
Copy link

TJackwood-Jasper commented Jul 1, 2022

@dmonad I'm seeing a similar issue now using Chrome as well.

I think the issue arises from the default WebSocket logic not "fully closing" for some reason; if I set up my y-websocket connection, then disconnect my connection between client and server, the client will eventually trigger the ws.close() here, but the websocket status sits forever in a CLOSING status and never actually transitions to a CLOSED state which would actually trigger the .onclose(...) logic.

Looks like the ws lib has struggled with this historically, but they have a timer running to forcibly close the connection fully if the other peer fails for a weird reason: websockets/ws#1125. Do you maybe need something similar here to prevent this CLOSING state limbo?

Edit: I reproduced this using Chrome devtools to set my client-side network throttling to "Offline" under the "Network" tab

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.

None yet

3 participants