Skip to content

Commit e60360e

Browse files
committed
net: remove cs_vRecvMsg
vRecvMsg is now only touched by the socket handler thread. The accounting vars (nRecvBytes/nLastRecv/mapRecvBytesPerMsgCmd) are also only used by the socket handler thread, with the exception of queries from rpc/gui. These accesses are not threadsafe, but they never were. This needs to be addressed separately. Also, update comment describing data flow
1 parent 991955e commit e60360e

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
lines changed

src/net.cpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,6 @@ void CNode::copyStats(CNodeStats &stats)
644644
}
645645
#undef X
646646

647-
// requires LOCK(cs_vRecvMsg)
648647
bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete)
649648
{
650649
complete = false;
@@ -1080,13 +1079,9 @@ void CConnman::ThreadSocketHandler()
10801079
TRY_LOCK(pnode->cs_vSend, lockSend);
10811080
if (lockSend)
10821081
{
1083-
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
1084-
if (lockRecv)
1085-
{
10861082
TRY_LOCK(pnode->cs_inventory, lockInv);
10871083
if (lockInv)
10881084
fDelete = true;
1089-
}
10901085
}
10911086
}
10921087
if (fDelete)
@@ -1146,15 +1141,10 @@ void CConnman::ThreadSocketHandler()
11461141
// write buffer in this case before receiving more. This avoids
11471142
// needlessly queueing received data, if the remote peer is not themselves
11481143
// receiving data. This means properly utilizing TCP flow control signalling.
1149-
// * Otherwise, if there is no (complete) message in the receive buffer,
1150-
// or there is space left in the buffer, select() for receiving data.
1151-
// * (if neither of the above applies, there is certainly one message
1152-
// in the receiver buffer ready to be processed).
1153-
// Together, that means that at least one of the following is always possible,
1154-
// so we don't deadlock:
1155-
// * We send some data.
1156-
// * We wait for data to be received (and disconnect after timeout).
1157-
// * We process a message in the buffer (message handler thread).
1144+
// * Otherwise, if there is space left in the receive buffer, select() for
1145+
// receiving data.
1146+
// * Hand off all complete messages to the processor, to be handled without
1147+
// blocking here.
11581148
{
11591149
TRY_LOCK(pnode->cs_vSend, lockSend);
11601150
if (lockSend) {
@@ -1165,8 +1155,7 @@ void CConnman::ThreadSocketHandler()
11651155
}
11661156
}
11671157
{
1168-
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
1169-
if (lockRecv && !pnode->fPauseRecv)
1158+
if (!pnode->fPauseRecv)
11701159
FD_SET(pnode->hSocket, &fdsetRecv);
11711160
}
11721161
}
@@ -1225,8 +1214,6 @@ void CConnman::ThreadSocketHandler()
12251214
continue;
12261215
if (FD_ISSET(pnode->hSocket, &fdsetRecv) || FD_ISSET(pnode->hSocket, &fdsetError))
12271216
{
1228-
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
1229-
if (lockRecv)
12301217
{
12311218
{
12321219
// typical socket buffer is 8K-64K
@@ -1865,14 +1852,8 @@ void CConnman::ThreadMessageHandler()
18651852
continue;
18661853

18671854
// Receive messages
1868-
{
1869-
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
1870-
if (lockRecv)
1871-
{
1872-
bool fMoreNodeWork = GetNodeSignals().ProcessMessages(pnode, *this, flagInterruptMsgProc);
1873-
fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend);
1874-
}
1875-
}
1855+
bool fMoreNodeWork = GetNodeSignals().ProcessMessages(pnode, *this, flagInterruptMsgProc);
1856+
fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend);
18761857
if (flagInterruptMsgProc)
18771858
return;
18781859

src/net.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,6 @@ class CNode
613613
size_t nProcessQueueSize;
614614

615615
std::deque<CInv> vRecvGetData;
616-
std::list<CNetMessage> vRecvMsg;
617-
CCriticalSection cs_vRecvMsg;
618616
uint64_t nRecvBytes;
619617
std::atomic<int> nRecvVersion;
620618

@@ -726,6 +724,7 @@ class CNode
726724
const ServiceFlags nLocalServices;
727725
const int nMyStartingHeight;
728726
int nSendVersion;
727+
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
729728
public:
730729

731730
NodeId GetId() const {
@@ -746,7 +745,6 @@ class CNode
746745
return nRefCount;
747746
}
748747

749-
// requires LOCK(cs_vRecvMsg)
750748
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
751749

752750
void SetRecvVersion(int nVersionIn)

src/net_processing.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
24392439
return true;
24402440
}
24412441

2442-
// requires LOCK(cs_vRecvMsg)
24432442
bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic<bool>& interruptMsgProc)
24442443
{
24452444
const CChainParams& chainparams = Params();

0 commit comments

Comments
 (0)