From 55555574d105f6c529c5c966c3c971c9db5ab786 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 23 Jul 2024 19:37:26 +0200 Subject: [PATCH] net: Log accepted connection after m_nodes.push_back Otherwise, the debug log could read confusingly, when the getpeerinfo() RPC (calling GetNodeStats) happens after the "accepted connection" log line, but returns an empty list. For example, the following timeline in the debug log could correspond to a getpeerinfo reply that is empty: [net] [net.cpp:3764] [CNode] Added connection peer=0 [net] [net.cpp:1814] [CreateNodeFromAcceptedSocket] connection from 127.0.0.1:45154 accepted [http] [httpserver.cpp:305] [http_request_cb] Received a POST request for / from 127.0.0.1:33320 [httpworker.1] [rpc/request.cpp:232] [parse] ThreadRPCServer method=getpeerinfo user=__cookie__ Fix it by moving the log line. --- src/net.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 3d3f9f4ba7d..ad43b316b32 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1810,13 +1810,11 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr&& sock, }); pnode->AddRef(); m_msgproc->InitializeNode(*pnode, nLocalServices); - - LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToStringAddrPort()); - { LOCK(m_nodes_mutex); m_nodes.push_back(pnode); } + LogDebug(BCLog::NET, "connection from %s accepted\n", addr.ToStringAddrPort()); // We received a new connection, harvest entropy from the time (and our peer count) RandAddEvent((uint32_t)id);