#35600 net: prevent duplication manual connections (take 2)
https://github.com/bitcoin/bitcoin/pull/35600 · · +164/-5 in 4 files, 2 commits · labels: P2P
Goal
- Prevent duplicate manual connections to the same target caused by concurrent connection attempts
- Stops duplicate sockets when -connect and -addnode are configured for the same destination
Tracks in-flight manual connection attempts in CConnman to prevent duplicate connections to the same target. Existing deduplication checks inspect connected peers in m_nodes only after a connection is established, allowing concurrent manual connection attempts to bypass checks. A functional regression test is also added.
Problem: When -connect and -addnode are configured for the same destination, startup threads can race to connect concurrently and create duplicate sockets to the same peer before either node is inserted into m_nodes.
Category: P2P (#31 of 65)
P3 · bug fix
- P3 because it fixes an edge-case race condition in manual connection management
- Affects only nodes configuring overlapping manual targets and does not threaten normal operation
P3 because it fixes an edge-case race condition in manual connection management where concurrent dials connect twice to the same address. As noted in the description, '-connect and -addnode can both try to open the same manual connection during startup' and 'two concurrent manual dial attempts can both pass the checks and create duplicate connections'. While resolving long-standing issue #5299, the failure requires overlapping manual connection configuration and does not threaten normal network operation.
Membership: Modifies manual connection tracking in CConnman in src/net.cpp and src/net.h.
Factors: security/stability 1, bug 1, performance 0, user value 1, leverage 0
Reviewability: Ready
- Ready to review now with clean code and no outstanding reviewer requests
The code is clean, CI passes, and there are no outstanding reviewer requests.
Author status: active
Agreement: Positive
- Positive sentiment with no objections raised
- Concept approval without stated reasons (sedited, w0xlt)
Positive: Concept ACKs from sedited and w0xlt with no objections.
Two contributors provided Concept ACKs with no objections or criticisms raised.
- sedited left a Concept ACK on 2026-07-24
- w0xlt left a Concept ACK on 2026-08-18
Review verdicts (DrahtBot): 0
Files
106 lines under test/bench/ci.
- test/functional/p2p_duplicate_manual_connections.py +105/-0
- src/net.cpp +52/-5
- src/net.h +6/-0
- test/functional/test_runner.py +1/-0
Card
This PR prevents duplicate manual P2P connections by reserving in-flight destinations in OpenNetworkConnection until the connection succeeds or fails. Currently, concurrent manual connection attempts (such as specifying both -connect and -addnode for the same peer at startup) can race past existing m_nodes deduplication checks before either socket completes. The problem primarily affects node operators with overlapping manual connection configurations, addressing long-standing issue #5299. The PR is ready for review with positive concept ACKs and no objections.