diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 70b07f8c..7a6a6b54 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All changes to this project will be documented in this file. +## [9.1.1] - 2020-03-26 + +(websocket) fix data race accessing _socket object without mutex protection when calling wakeUpFromPoll in WebSocketTransport.cpp + ## [9.1.0] - 2020-03-26 (ixcobra) add explicit event types for handshake, authentication and subscription failure, and handle those by exiting in ws_cobra_subcribe and friends diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index 946d3878..df80cd58 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -625,7 +625,7 @@ namespace ix // send back the CLOSE frame sendCloseFrame(code, reason); - _socket->wakeUpFromPoll(Socket::kCloseRequest); + wakeUpFromPoll(Socket::kCloseRequest); bool remote = true; closeSocketAndSwitchToClosedState(code, reason, _rxbuf.size(), remote); @@ -845,7 +845,7 @@ namespace ix // Request to flush the send buffer on the background thread if it isn't empty if (!isSendBufferEmpty()) { - _socket->wakeUpFromPoll(Socket::kSendRequest); + wakeUpFromPoll(Socket::kSendRequest); // FIXME: we should have a timeout when sending large messages: see #131 if (_blockingSend && !flushSendBuffer()) @@ -1063,6 +1063,12 @@ namespace ix _socket->close(); } + bool WebSocketTransport::wakeUpFromPoll(uint64_t wakeUpCode) + { + std::lock_guard lock(_socketMutex); + return _socket->wakeUpFromPoll(wakeUpCode); + } + void WebSocketTransport::closeSocketAndSwitchToClosedState(uint16_t code, const std::string& reason, size_t closeWireSize, @@ -1110,8 +1116,9 @@ namespace ix setReadyState(ReadyState::CLOSING); sendCloseFrame(code, reason); + // wake up the poll, but do not close yet - _socket->wakeUpFromPoll(Socket::kSendRequest); + wakeUpFromPoll(Socket::kSendRequest); } size_t WebSocketTransport::bufferedAmount() const diff --git a/ixwebsocket/IXWebSocketTransport.h b/ixwebsocket/IXWebSocketTransport.h index e3c5df20..91ad564a 100644 --- a/ixwebsocket/IXWebSocketTransport.h +++ b/ixwebsocket/IXWebSocketTransport.h @@ -229,6 +229,8 @@ namespace ix size_t closeWireSize, bool remote); + bool wakeUpFromPoll(uint64_t wakeUpCode); + bool flushSendBuffer(); bool sendOnSocket(); bool receiveFromSocket(); diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index d4573a2b..4557837d 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "9.1.0" +#define IX_WEBSOCKET_VERSION "9.1.1"