[Webkit-unassigned] [Bug 247943] REGRESSION (Safari 15.6.1-16.1): WebSocket in latest Safari does not emit onclose event when internet is turned off (wifi or cellular)

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Nov 18 01:39:21 PST 2022


https://bugs.webkit.org/show_bug.cgi?id=247943

--- Comment #11 from Mike <poremba at nolimit.sk> ---
We primary take care about mobile devices. Chrome and others on iOS is not widely used. Anyway Firefox and Chrome on iOS have the same issue as Safari nowadays because they use WebKit too. Chrome on Android fires WebSocket CLOSE event immediately when internet is disconnected. It is reliable because we have tested also ancient devices with ancient Chrome (e.g. since Android v4.2, Chrome v37) and also modern devices from different manufactures with latest Chrome and behavior is the same with no problem. Also Firefox on Android fires CLOSE event immediately. Problem is in iOS WebKit browsers where behavior has been changed as you wrote since NSURLSession WebSocket is used.

How to handle it? I think the only one solution is to manually close connection when offline event is fired window.addEventListener('offline'), () => { ws.close() }) and on online event create a new one window.addEventListener('offline'), () => { var ws = new WebSocket(...) }) I think each developer must do it now because as mentioned in screen https://dev.bikeapp.sk/apple-bugs/2/Screen%20Shot%202022-11-16%20at%2013.16.33%20with%20note.png websocket connection after internet off/on is not reliable. So question is what sense have to do not fire close event automatically? Is it possible to change NSURLSession WebSocket behavior (fire close event on internet disconnected)? As I already mentioned close event is fired when phone is locked or app minimized, so it is expected to be fired when internet is disconnected.

New test: https://dev.bikeapp.sk/apple-bugs/2/Screen%20Shot%202022-11-18%20at%2010.03.13%20with%20note.png
On macOS Firefox closes websocket connection 10 seconds after internet disconnection, Chrome after 10 minutes and Safari seems never. All these browsers on iOS never fires close event because they use the same WebKit. So I think changing NSURLSession WebSocket behavior have sense.

It is not desired to consider websocket connection on client side as working after so long time after internet is disconnected. Author of "ws" lib recommends here https://github.com/websockets/ws#how-to-detect-and-close-broken-connections to consider clients not responding to ping for more then 30 secs (+ latency) to be zombie and must be terminated. This MUST BE always implemented by each developer because zombie connections can spend server resources. We also implemented it (except debug tool website to demonstrate that Safari websocket connection is not alive after some time although it is still in readyState OPEN).

So it would be great to change NSURLSession WebSocket:

A) fire close event immediately after internet is disconnected (identical behavior as in older Safari versions),

B) or inspire by Chrome and Firefox (those on macOs which are not using WebKit) and close connection after some fixed time.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20221118/7d972def/attachment.htm>


More information about the webkit-unassigned mailing list