Y-Websocket data loss on iPhone/iPad/MacOS Safari when network changes

This topic is an FYI for any members of the community using Y-Websocket who have users on iPhone/iPad/MacOS (Safari).

There is a pretty bad bug in Webkit which has been open for a while where it doesn’t fire the onclose/onerror events when the connection drops due to network changes (such as switching from Wi-Fi to cellular) and which will cause any subsequent user data sent to the Websocket to be lost without any errors being raised.

I was getting a stream of user complaints that data was being lost, primarily from users on iPhone.

I filed an issue in Y-Websocket but wanted to post here too so that any other users of the library can hopefully find it before their users run into data loss issues.

I worked around the issue by implementing a heartbeat protocol in my front and backend to detect loss of connectivity and manually recreate the underlying websocket to reestablish the connection.

3 Likes