Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

websocket onclose not triggered in chrome - linux when client is disconnected from the network

I implemented websocket by using java in server side. In client I created websocket object, and I have my own function for all the events including onClose. I tested reconnection... websocket in chrome 26, Mozilla both windows and chrome.

Chrome in windows triggers onclose event when I plugged out the network cable (i.e onclose triggers with closecode 1006 [abnormaly closed] as mentioned in https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent) but Chrome in linux does not trigger any event.

Please suggest what mistake I did.

My exact question is why chrome in windows triggers onclose when network is disconnected, but in case of linux, it is not triggered.

like image 372
raky Avatar asked Oct 04 '22 01:10

raky


1 Answers

It is possible that these applications do not notice the TCP connection breaking down. A timeout is used to detect a failing TCP connection, and I believe the default timeout is quite long.

The browser/OS should notice that the connection is gone as soon as you try to send data. Try sending some data after unplugging the network cable, see if that triggers the event.

Also, how long have you waited for the signal? Maybe the connection just has a long TCP timeout.

If you still do not get a closed event it is likely due to a fault in the implementation. If you absolutely need to know when the connection breaks down, implement a ping mechanism with your own timeout. I believe the websocket protocol defines its own ping protocol, maybe look into that.

Also, for chrome there seems to be an issue filed for this. Maybe it'll help you.

like image 102
Wutz Avatar answered Oct 13 '22 11:10

Wutz