diff --git a/src/net.cpp b/src/net.cpp index 735985a8414..0418fd07da2 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1910,7 +1910,8 @@ void CConnman::DisconnectNodes() { LOCK(m_nodes_mutex); - if (!fNetworkActive) { + const bool network_active{fNetworkActive}; + if (!network_active) { // Disconnect any connected nodes for (CNode* pnode : m_nodes) { if (!pnode->fDisconnect) { @@ -1932,7 +1933,7 @@ void CConnman::DisconnectNodes() // Add to reconnection list if appropriate. We don't reconnect right here, because // the creation of a connection is a blocking operation (up to several seconds), // and we don't want to hold up the socket handler thread for that long. - if (pnode->m_transport->ShouldReconnectV1()) { + if (network_active && pnode->m_transport->ShouldReconnectV1()) { reconnections_to_add.push_back({ .addr_connect = pnode->addr, .grant = std::move(pnode->grantOutbound),