Repository navigation
net: prevent duplication manual connections (take 2) - #35600
willcl-ark wants to merge 2 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsNo conflicts as of last run. |
|
Concept ACK |
f80f522 to
cec131b
Compare
|
Concept ACK |
cec131b to
081ba2b
Compare
|
ACK 081ba2b Built and ran the new test, the functional suite and the net unit tests. The new test fails with the duplicate check disabled, and also when the key normalization or the release after a failed attempt is broken. The test still passes if the reservation covers every connection type (net.cpp:3139). An |
081ba2b to
590947d
Compare
|
ACK 590947d I think this also partially fixes #22559. In there, there is another bug that it is related and I think it may make sense to address it in this PR. I left my suggestions in the comments of the issue so feel free to check it out or ignore it if you think it deserve its own pr. That being said, I tested the code by passing the test and also in I2P. In I2P it is very easy to reproduce this bug. You can do so by connecting to the same address multiple times at the same time: ./build/bin/bitcoin-cli addnode "$ADDR" onetry &
./build/bin/bitcoin-cli addnode "$ADDR" onetry &
waitWith this you can create duplicated connections to your node (as many as you want in theory, I've just tried with 3 duplicated connections). If you run the comand above after the fix of this pr, the duplicates connections are gone. |
Concurrent -connect and -addnode attempts could pass connected-peer checks before either published a node. Reserve a normalized destination until the dial fails or its node enters m_nodes. Check connected peers while holding the reservation, so proxied hostnames cannot use a stale precheck. Keep the reservation scoped to this call and leave the addnode scheduler unchanged. Numeric destinations include their port; unresolved hostnames use the original string without an extra DNS lookup.
The startup topology alone can pass without exercising pending-attempt exclusion. Hold one manual connection in a local proxy handshake and require a second attempt to be rejected while the first is pending.
|
Thanks for reviewing @Bicaru20. I agree that this PR only partially fixes #22559, but I think in this case I'm going to leave the fix for that up to a separate PR as IMO the nonce tie-breaker probably wants some decent independent scrutiny. I'd encourage you (or anyone) to perhaps followup this PR with a complete fix for it though! |
590947d to
120d45e
Compare

Fixes #5299.
-connectand-addnodecan attempt the same manual connection concurrently during startup. The existing duplicate checks cannot see a peer until it has been added tom_nodes, so both attempts can pass and open connections.Reserve the destination in
OpenNetworkConnection()before checking connected peers or starting the connection. The reservation stays in place until the attempt fails or the new peer has been added tom_nodes.This applies to
ConnectionType::MANUAL, including-connect,-addnode, manual reconnections, andaddnode onetry. Automatic outbound connections are outside this change.The functional test checks the original two-node startup case. It also holds a manual connection in a local proxy handshake and verifies that an overlapping attempt is rejected, that a failed attempt releases its reservation, and that equivalent numeric addresses share a reservation.
Unlike #27804, this handles attempts in the connection manager rather than deduplicating configuration arguments. Hostnames use their original string as the reservation key, so different names that resolve to the same endpoint may still overlap. This avoids an extra DNS lookup.