Skip to content

Commit f30f10e

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 5812f9e commit f30f10e

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6099,7 +6099,6 @@ int ActiveProtocol()
60996099
return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT;
61006100
}
61016101

6102-
// requires LOCK(cs_vRecvMsg)
61036102
bool ProcessMessages(CNode* pfrom, CConnman& connman, std::atomic<bool>& interruptMsgProc)
61046103
{
61056104
// Message format

src/net.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,6 @@ void CNode::copyStats(CNodeStats& stats)
693693
}
694694
#undef X
695695

696-
// requires LOCK(cs_vRecvMsg)
697696
bool CNode::ReceiveMsgBytes(const char* pch, unsigned int nBytes, bool& complete)
698697
{
699698
complete = false;
@@ -1086,12 +1085,9 @@ void CConnman::ThreadSocketHandler()
10861085
{
10871086
TRY_LOCK(pnode->cs_vSend, lockSend);
10881087
if (lockSend) {
1089-
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
1090-
if (lockRecv) {
10911088
TRY_LOCK(pnode->cs_inventory, lockInv);
10921089
if (lockInv)
10931090
fDelete = true;
1094-
}
10951091
}
10961092
}
10971093
if (fDelete) {
@@ -1149,15 +1145,10 @@ void CConnman::ThreadSocketHandler()
11491145
// write buffer in this case before receiving more. This avoids
11501146
// needlessly queueing received data, if the remote peer is not themselves
11511147
// receiving data. This means properly utilizing TCP flow control signalling.
1152-
// * Otherwise, if there is no (complete) message in the receive buffer,
1153-
// or there is space left in the buffer, select() for receiving data.
1154-
// * (if neither of the above applies, there is certainly one message
1155-
// in the receiver buffer ready to be processed).
1156-
// Together, that means that at least one of the following is always possible,
1157-
// so we don't deadlock:
1158-
// * We send some data.
1159-
// * We wait for data to be received (and disconnect after timeout).
1160-
// * We process a message in the buffer (message handler thread).
1148+
// * Otherwise, if there is space left in the receive buffer, select() for
1149+
// receiving data.
1150+
// * Hand off all complete messages to the processor, to be handled without
1151+
// blocking here.
11611152
{
11621153
LOCK(pnode->cs_vSend);
11631154
if (!pnode->vSendMsg.empty()) {
@@ -1166,8 +1157,7 @@ void CConnman::ThreadSocketHandler()
11661157
}
11671158
}
11681159
{
1169-
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
1170-
if (lockRecv && !pnode->fPauseRecv)
1160+
if (!pnode->fPauseRecv)
11711161
FD_SET(pnode->hSocket, &fdsetRecv);
11721162
}
11731163
}
@@ -1220,8 +1210,7 @@ void CConnman::ThreadSocketHandler()
12201210
if (pnode->hSocket == INVALID_SOCKET)
12211211
continue;
12221212
if (FD_ISSET(pnode->hSocket, &fdsetRecv) || FD_ISSET(pnode->hSocket, &fdsetError)) {
1223-
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
1224-
if (lockRecv) {
1213+
{
12251214
{
12261215
// typical socket buffer is 8K-64K
12271216
char pchBuf[0x10000];
@@ -1807,13 +1796,8 @@ void CConnman::ThreadMessageHandler()
18071796
continue;
18081797

18091798
// Receive messages
1810-
{
1811-
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
1812-
if (lockRecv) {
1813-
bool fMoreNodeWork = GetNodeSignals().ProcessMessages(pnode, *this, flagInterruptMsgProc);
1814-
fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend);
1815-
}
1816-
}
1799+
bool fMoreNodeWork = GetNodeSignals().ProcessMessages(pnode, *this, flagInterruptMsgProc);
1800+
fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend);
18171801
if (flagInterruptMsgProc)
18181802
return;
18191803

src/net.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,6 @@ class CNode
583583
RecursiveMutex cs_sendProcessing;
584584

585585
std::deque<CInv> vRecvGetData;
586-
std::list<CNetMessage> vRecvMsg;
587-
RecursiveMutex cs_vRecvMsg;
588586
uint64_t nRecvBytes;
589587
std::atomic<int> nRecvVersion;
590588

@@ -674,6 +672,7 @@ class CNode
674672
const ServiceFlags nLocalServices;
675673
const int nMyStartingHeight;
676674
int nSendVersion;
675+
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
677676
public:
678677
NodeId GetId() const
679678
{
@@ -694,7 +693,6 @@ class CNode
694693
return nRefCount;
695694
}
696695

697-
// requires LOCK(cs_vRecvMsg)
698696
unsigned int GetTotalRecvSize()
699697
{
700698
unsigned int total = 0;
@@ -703,7 +701,6 @@ class CNode
703701
return total;
704702
}
705703

706-
// requires LOCK(cs_vRecvMsg)
707704
bool ReceiveMsgBytes(const char* pch, unsigned int nBytes, bool& complete);
708705

709706
void SetRecvVersion(int nVersionIn)

0 commit comments

Comments
 (0)