Skip to content

Commit

Permalink
Merge pull request #1294 from paullouisageneau/tcptransport-sendmutex
Browse files Browse the repository at this point in the history
Fix lock order inversion in TcpTransport
  • Loading branch information
paullouisageneau authored Nov 28, 2024
2 parents 5d3e79c + a1bd307 commit e80ba94
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/impl/tcptransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit e80ba94

Please sign in to comment.