From a1bd3071177ce400561e0807166e2eb3246fc77a Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Fri, 22 Nov 2024 23:49:58 +0100 Subject: [PATCH] Fix lock order inversion in TcpTransport --- src/impl/tcptransport.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/impl/tcptransport.cpp b/src/impl/tcptransport.cpp index a83fda958..9f1a64a95 100644 --- a/src/impl/tcptransport.cpp +++ b/src/impl/tcptransport.cpp @@ -200,23 +200,23 @@ void TcpTransport::resolve() { } void TcpTransport::attempt() { - std::lock_guard lock(mSendMutex); + try { + std::lock_guard lock(mSendMutex); - if (state() != State::Connecting) - return; // Cancelled + if (state() != State::Connecting) + return; // Cancelled - if (mSock == INVALID_SOCKET) { - ::closesocket(mSock); - mSock = INVALID_SOCKET; - } + if (mSock == INVALID_SOCKET) { + ::closesocket(mSock); + mSock = INVALID_SOCKET; + } - if (mResolved.empty()) { - PLOG_WARNING << "Connection to " << mHostname << ":" << mService << " failed"; - changeState(State::Failed); - return; - } + if (mResolved.empty()) { + PLOG_WARNING << "Connection to " << mHostname << ":" << mService << " failed"; + changeState(State::Failed); + return; + } - try { auto [addr, addrlen] = mResolved.front(); mResolved.pop_front();