From 673254515a2f97e53dd8c7335c836b083ba7e31a Mon Sep 17 00:00:00 2001 From: John Newbery Date: Sun, 27 Dec 2020 09:22:04 +0000 Subject: [PATCH 1/2] [net] Move RecordBytesSent() call out of cs_vSend lock --- src/net.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 7df0d11d375f4..3b1c19f60abf9 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1512,16 +1512,10 @@ void CConnman::SocketHandler() } } - // - // Send - // - if (sendSet) - { - LOCK(pnode->cs_vSend); - size_t nBytes = SocketSendData(pnode); - if (nBytes) { - RecordBytesSent(nBytes); - } + if (sendSet) { + // Send data + size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(pnode)); + if (bytes_sent) RecordBytesSent(bytes_sent); } InactivityCheck(pnode); From 378aedc45248cea82d9a3e6dc1038d6828008a76 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Sun, 27 Dec 2020 09:28:04 +0000 Subject: [PATCH 2/2] [net] Add cs_vSend lock annotations --- src/net.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/net.h b/src/net.h index 1520a54686f4e..2b97d611843d9 100644 --- a/src/net.h +++ b/src/net.h @@ -857,8 +857,10 @@ class CNode // socket std::atomic nServices{NODE_NONE}; SOCKET hSocket GUARDED_BY(cs_hSocket); - size_t nSendSize{0}; // total size of all vSendMsg entries - size_t nSendOffset{0}; // offset inside the first vSendMsg already sent + /** Total size of all vSendMsg entries */ + size_t nSendSize GUARDED_BY(cs_vSend){0}; + /** Offset inside the first vSendMsg already sent */ + size_t nSendOffset GUARDED_BY(cs_vSend){0}; uint64_t nSendBytes GUARDED_BY(cs_vSend){0}; std::deque> vSendMsg GUARDED_BY(cs_vSend); RecursiveMutex cs_vSend; @@ -989,7 +991,7 @@ class CNode Network ConnectedThroughNetwork() const; protected: - mapMsgCmdSize mapSendBytesPerMsgCmd; + mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend); mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv); public: