Skip to content

Commit e8a2822

Browse files
committed
[net] Don't try to take cs_inventory before deleting CNode
The TRY_LOCK(cs_inventory) in DisconnectNodes() is taken after the CNode object has been removed from vNodes and when the CNode's nRefCount is zero. The only other places that cs_inventory can be taken are: - In ProcessMessages() or SendMessages(), when the CNode's nRefCount must be >0 (see ThreadMessageHandler(), where the refcount is incremented before calling ProcessMessages() and SendMessages()). - In a ForEachNode() lambda in PeerLogicValidation::UpdatedBlockTip(). ForEachNode() locks cs_vNodes and calls the function on the CNode objects in vNodes. Therefore, cs_inventory is never locked by another thread when the TRY_LOCK(cs_inventory) is reached in DisconnectNodes(). Since the only purpose of this TRY_LOCK is to ensure that the lock is not taken by another thread, this always succeeds. Remove the check.
1 parent 3556227 commit e8a2822

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/net.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,12 +1103,9 @@ void CConnman::DisconnectNodes()
11031103
if (pnode->GetRefCount() <= 0) {
11041104
bool fDelete = false;
11051105
{
1106-
TRY_LOCK(pnode->cs_inventory, lockInv);
1107-
if (lockInv) {
1108-
TRY_LOCK(pnode->cs_vSend, lockSend);
1109-
if (lockSend) {
1110-
fDelete = true;
1111-
}
1106+
TRY_LOCK(pnode->cs_vSend, lockSend);
1107+
if (lockSend) {
1108+
fDelete = true;
11121109
}
11131110
}
11141111
if (fDelete) {

0 commit comments

Comments
 (0)