From e1abcb0f2373cc8f1ef78c688aa314dc239f499a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Jul 2020 12:43:58 +0200 Subject: [PATCH] fix: fixed threading issue (unsychronized access to wsi_) --- test/webfuse/test_util/ws_client.cc | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/webfuse/test_util/ws_client.cc b/test/webfuse/test_util/ws_client.cc index d19a189..d074f7b 100644 --- a/test/webfuse/test_util/ws_client.cc +++ b/test/webfuse/test_util/ws_client.cc @@ -121,7 +121,9 @@ public: ~Private() { - Invoke(command::shutdown); + std::unique_lock lock(mutex); + commands.push(command::shutdown); + lock.unlock(); lws_cancel_service(context); thread.join(); @@ -356,10 +358,18 @@ private: } break; case command::disconnect: - lws_callback_on_writable(self->wsi_); - break; + // fallthrough case command::send: - lws_callback_on_writable(self->wsi_); + { + std::unique_lock lock(self->mutex); + lws * wsi = self->wsi_; + lock.unlock(); + + if (nullptr != wsi) + { + lws_callback_on_writable(wsi); + } + } break; default: break; @@ -381,12 +391,6 @@ private: return command; } - void Invoke(command command) - { - std::unique_lock lock(mutex); - commands.push(command); - } - lws * wsi_; InvokationHandler & handler_; std::string protocol_;