Skip to content

Commit a0701e9

Browse files
committed
merge bitcoin#26515: skip getpeerinfo for a peer without CNodeStateStats
1 parent c9eedc8 commit a0701e9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/rpc/net.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ static RPCHelpMan getpeerinfo()
196196
UniValue obj(UniValue::VOBJ);
197197
CNodeStateStats statestats;
198198
bool fStateStats = peerman.GetNodeStateStats(stats.nodeid, statestats);
199+
// GetNodeStateStats() requires the existence of a CNodeState and a Peer object
200+
// to succeed for this peer. These are created at connection initialisation and
201+
// exist for the duration of the connection - except if there is a race where the
202+
// peer got disconnected in between the GetNodeStats() and the GetNodeStateStats()
203+
// calls. In this case, the peer doesn't need to be reported here.
204+
if (!fStateStats) {
205+
continue;
206+
}
199207
obj.pushKV("id", stats.nodeid);
200208
obj.pushKV("addr", stats.m_addr_name);
201209
if (stats.addrBind.IsValid()) {

0 commit comments

Comments
 (0)