IXWebSocket icon indicating copy to clipboard operation
IXWebSocket copied to clipboard

No Close event when server TCP socket closed

Open mduint32 opened this issue 2 years ago • 2 comments

I'm investigating an issue where a linux client application using ix::WebSocket sometimes doesn't react to a websocket server (not IXWebSocket) closing its TCP socket. This is not a graceful websocket close handshake, but on TCP level a RST is being sent (according to WireShark) so the client is actually notified that the connection goes away.

Sometimes this results in the OnMessageCallback being called with a Close message with "abnormal closure" and sometimes it doesn't. When it doesn't, the next time any message is sent (either websocket ping or a regular message) it seems to realize the connection has failed and the OnMessageCallback is called with a Close message with "internal error".

My investigation so far has taken me to WebSocketTransport::poll: if _socket->isReadyToRead returns PollResultType::Error, it calls closeSocket, but the function will still return PollResult::Succeeded.

https://github.com/machinezone/IXWebSocket/blob/f79c64ae9741796acf4144ec86336880b644463d/ixwebsocket/IXWebSocketTransport.cpp#L377

Won't that mean WebSocket::run will keep retrying poll on a closed socket? Is that intentional?

I experimented with adding return PollResult::AbnormalClose; after closeSocket in that if clause. It improved behavior in my case: I reliably get Close directly and with "abnormal closure".

mduint32 avatar May 23 '23 11:05 mduint32

me too

engun avatar Jun 26 '23 14:06 engun

Same here, server is stopped but no Close event is received. @mduint32, have you found any downsides to your fix? Should we make a PR?

MichelJansson avatar Nov 24 '23 17:11 MichelJansson