Skip to content

Commit

Permalink
[net processing] Add comment about destructing Peer objects
Browse files Browse the repository at this point in the history
Suggested here: bitcoin#19607 (comment)
  • Loading branch information
jnewbery committed Nov 19, 2020
1 parent cddcd22 commit e679b8d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ void PeerManager::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) {
LOCK(cs_main);
int misbehavior{0};
{
// We remove the PeerRef from g_peer_map here, but we don't always
// destruct the Peer. Sometimes another thread is still holding a
// PeerRef, so the refcount is >= 1. Be careful not to do any
// processing here that assumes Peer won't be changed before it's
// destructed.
PeerRef peer = GetPeerRef(nodeid);
assert(peer != nullptr);
misbehavior = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_misbehavior_score);
Expand Down

0 comments on commit e679b8d

Please sign in to comment.