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
This commit is contained in:
David Capello 2023-09-01 12:11:36 -03:00 committed by GitHub
parent 28832f8732
commit ef57e3a2b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1174,7 +1174,22 @@ namespace ix
{ {
_requestInitCancellation = true; _requestInitCancellation = true;
if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED) return; if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED)
{
// Wake up the socket polling thread, as
// Socket::isReadyToRead() might be still waiting the
// interrupt event to happen.
bool wakeUpPoll = false;
{
std::lock_guard<std::mutex> lock(_socketMutex);
wakeUpPoll = (_socket && _socket->isWakeUpFromPollSupported());
}
if (wakeUpPoll)
{
wakeUpFromPoll(SelectInterrupt::kCloseRequest);
}
return;
}
if (closeWireSize == 0) if (closeWireSize == 0)
{ {