Skip to content

Commit ec23964

Browse files
TheBlueMattfurszy
authored andcommitted
Split CNode::cs_vSend: message processing and message sending
cs_vSend is used for two purposes - to lock the datastructures used to queue messages to place on the wire and to only call SendMessages once at a time per-node. I believe SendMessages used to access some of the vSendMsg stuff, but it doesn't anymore, so these locks do not need to be on the same mutex, and also make deadlocking much more likely.
1 parent f9c458a commit ec23964

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/net.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,8 @@ void ThreadSocketHandler()
12251225
// * We wait for data to be received (and disconnect after timeout).
12261226
// * We process a message in the buffer (message handler thread).
12271227
{
1228-
TRY_LOCK(pnode->cs_vSend, lockSend);
1229-
if (lockSend && !pnode->vSendMsg.empty()) {
1228+
LOCK(pnode->cs_vSend);
1229+
if (!pnode->vSendMsg.empty()) {
12301230
FD_SET(pnode->hSocket, &fdsetSend);
12311231
continue;
12321232
}
@@ -1320,9 +1320,8 @@ void ThreadSocketHandler()
13201320
if (pnode->hSocket == INVALID_SOCKET)
13211321
continue;
13221322
if (FD_ISSET(pnode->hSocket, &fdsetSend)) {
1323-
TRY_LOCK(pnode->cs_vSend, lockSend);
1324-
if (lockSend)
1325-
SocketSendData(pnode);
1323+
LOCK(pnode->cs_vSend);
1324+
SocketSendData(pnode);
13261325
}
13271326

13281327
//
@@ -1842,7 +1841,7 @@ void ThreadMessageHandler()
18421841

18431842
// Send messages
18441843
{
1845-
TRY_LOCK(pnode->cs_vSend, lockSend);
1844+
TRY_LOCK(pnode->cs_sendProcessing, lockSend);
18461845
if (lockSend)
18471846
GetNodeSignals().SendMessages(pnode);
18481847
}

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ class CNode
321321
std::deque<CSerializeData> vSendMsg;
322322
RecursiveMutex cs_vSend;
323323

324+
RecursiveMutex cs_sendProcessing;
325+
324326
std::deque<CInv> vRecvGetData;
325327
std::deque<CNetMessage> vRecvMsg;
326328
RecursiveMutex cs_vRecvMsg;

0 commit comments

Comments
 (0)