diff --git a/src/net.cpp b/src/net.cpp index 28dbc0850..b9634b2e0 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1050,6 +1050,9 @@ void ThreadSocketHandler() if (pnode->fDisconnect || (pnode->GetRefCount() <= 0 && pnode->vRecvMsg.empty() && pnode->nSendSize == 0 && pnode->ssSend.empty())) { + LogPrintf("ThreadSocketHandler -- removing node: peer=%d addr=%s nRefCount=%d fNetworkNode=%d fInbound=%d fMasternode=%d\n", + pnode->id, pnode->addr.ToString(), pnode->GetRefCount(), pnode->fNetworkNode, pnode->fInbound, pnode->fMasternode); + // remove from vNodes vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end()); diff --git a/src/net.h b/src/net.h index 8a39577b1..76bf4901b 100644 --- a/src/net.h +++ b/src/net.h @@ -436,6 +436,8 @@ private: static uint64_t nMaxOutboundLimit; static uint64_t nMaxOutboundTimeframe; + CCriticalSection cs_nRefCount; + CNode(const CNode&); void operator=(const CNode&); @@ -447,6 +449,7 @@ public: int GetRefCount() { + LOCK(cs_nRefCount); assert(nRefCount >= 0); return nRefCount; } @@ -473,12 +476,14 @@ public: CNode* AddRef() { + LOCK(cs_nRefCount); nRefCount++; return this; } void Release() { + LOCK(cs_nRefCount); nRefCount--; assert(nRefCount >= 0); }