That’s unfortunate that we call a logging function while holding a lock. Maybe
0--- a/src/net_processing.cpp
1+++ b/src/net_processing.cpp
2@@ -2697,10 +2696,15 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
3 void PeerManagerImpl::UpdatePeerStateForReceivedHeaders(CNode& pfrom, Peer& peer,
4 const CBlockIndex& last_header, bool received_new_header, bool may_have_more_headers)
5 {
6- if (peer.nUnconnectingHeaders > 0) {
7- LogPrint(BCLog::NET, "peer=%d: resetting nUnconnectingHeaders (%d -> 0)\n", pfrom.GetId(), peer.nUnconnectingHeaders);
8+ int num_unconnecting_headers_msgs;
9+ {
10+ LOCK(NetEventsInterface::g_msgproc_mutex);
11+ num_unconnecting_headers_msgs = peer.nUnconnectingHeaders;
12+ peer.nUnconnectingHeaders = 0;
13+ }
14+ if (num_unconnecting_headers_msgs > 0) {
15+ LogPrint(BCLog::NET, "peer=%d: resetting nUnconnectingHeaders (%d -> 0)\n", pfrom.GetId(), num_unconnecting_headers_msgs);
16 }
17- peer.nUnconnectingHeaders = 0;
18
19 LOCK(cs_main);
20 CNodeState *nodestate = State(pfrom.GetId());
and drop EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex)
annotation?