Skip to content

Commit ef57e3a

Browse files
authored
Fix hanging of WebSocket::stop() waiting for its thread to join (#481)
This might happen in some special cases where WebSocketTransport::sendOnSocket() fails, closes the socket, and set the ready state to CLOSED, but WebSocket::run() stills wait the interrupt event to happen. Possibly related to #474
1 parent 28832f8 commit ef57e3a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ixwebsocket/IXWebSocketTransport.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,22 @@ namespace ix
11741174
{
11751175
_requestInitCancellation = true;
11761176

1177-
if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED) return;
1177+
if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED)
1178+
{
1179+
// Wake up the socket polling thread, as
1180+
// Socket::isReadyToRead() might be still waiting the
1181+
// interrupt event to happen.
1182+
bool wakeUpPoll = false;
1183+
{
1184+
std::lock_guard<std::mutex> lock(_socketMutex);
1185+
wakeUpPoll = (_socket && _socket->isWakeUpFromPollSupported());
1186+
}
1187+
if (wakeUpPoll)
1188+
{
1189+
wakeUpFromPoll(SelectInterrupt::kCloseRequest);
1190+
}
1191+
return;
1192+
}
11781193

11791194
if (closeWireSize == 0)
11801195
{

0 commit comments

Comments
 (0)