IXWebSocket icon indicating copy to clipboard operation
IXWebSocket copied to clipboard

the client did not receive the close event

Open engun opened this issue 2 years ago • 5 comments

System: Windows 11 64-bit.

This lib is great. Although there were some issues encountered during use

When the server is abnormally shut down, the client did not receive the close event. It seems that the FD_CLOSE event should be taken into account in WSAWaitForMultipleEvents in IXNetSystem::poll.

engun avatar Jun 26 '23 17:06 engun

Thanks for the good words, it's possible there are some holes in the IXNetSystem::poll.

If you want to submit a PR we can try to evaluate it and merge it.

I code on macOS and Linux, so I'm not the best person to fix advanced windows problem sadly.

bsergean avatar Jul 01 '23 00:07 bsergean

It's probable that there is a missing wakeUpFromPoll() call from WebSocketTransport::close() to unlock the WebSocket::stop() function which is waiting for a _thread.join() (this thread is running WebSocket::run() which calls WebSocketTransport::poll() that can be waken up only if wakeUpFromPoll() is called again):

diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp
index ec25465..8049fb6 100644
--- a/ixwebsocket/IXWebSocketTransport.cpp
+++ b/ixwebsocket/IXWebSocketTransport.cpp
@@ -1174,7 +1174,10 @@ namespace ix
     {
         _requestInitCancellation = true;
 
-        if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED) return;
+        if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED) {
+            wakeUpFromPoll(SelectInterrupt::kSendRequest);
+            return;
+        }
 
         if (closeWireSize == 0)
         {

dacap avatar Aug 22 '23 21:08 dacap

@dacap If you make a PR for this change we can give it a try on CI.

bsergean avatar Aug 23 '23 01:08 bsergean

This problem still persists even with latest version. Only on Windows. On MacOS it alright.

Longwater1234 avatar Jul 09 '24 12:07 Longwater1234

Might be fixed with https://github.com/machinezone/IXWebSocket/pull/548

bsergean avatar May 14 '25 18:05 bsergean