From de93f8be5bc177cca0b4abf42f2e2b08c0ec9592 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 11 Jan 2021 01:15:28 +0100 Subject: [PATCH] Fix race condition when setting the request state to active Call SetState(State_Active) before signalling the worker thread, as otherwise it would be possible for it to wake up and set its state to something else before it was reset to "active" from the main thread. This fixed another TSAN error. --- src/common/webrequest_curl.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/webrequest_curl.cpp b/src/common/webrequest_curl.cpp index 0b67cab259..16527faf2f 100644 --- a/src/common/webrequest_curl.cpp +++ b/src/common/webrequest_curl.cpp @@ -230,16 +230,13 @@ bool wxWebRequestCURL::StartRequest() { m_bytesSent = 0; - if ( m_sessionImpl.StartRequest(*this) ) - { - SetState(wxWebRequest::State_Active); - return true; - } - else + if ( !m_sessionImpl.StartRequest(*this) ) { SetState(wxWebRequest::State_Failed); return false; } + + return true; } void wxWebRequestCURL::Cancel() @@ -517,6 +514,8 @@ bool wxWebSessionCURL::StartRequest(wxWebRequestCURL & request) return false; } + request.SetState(wxWebRequest::State_Active); + // Signal the worker thread to resume work wxMutexLocker lock(m_mutex); m_condition.Signal();