Commit 0933cf5
net: fix race condition in self-connect detection
Initiating an outbound network connection currently involves the
following steps after the socket connection is established (see
`CConnman::OpenNetworkConnection` method):
1. set up node state
2. queue VERSION message
3. add new node to vector `m_nodes`
If we connect to ourself, it can happen that the sent VERSION message
(step 2) is received and processed locally *before* the node object
is added to the connection manager's `m_nodes` vector (step 3). In this
case, the self-connect remains undiscovered, as the detection doesn't
find the outbound peer in `m_nodes` yet (see `CConnman::CheckIncomingNonce`).
Fix this by swapping the order of 2. and 3., by taking the `PushNodeVersion`
call out of `InitializeNode` and doing that in the `SendMessages` method
instead, which is only called for `CNode` instances in `m_nodes`.
Thanks go to vasild, mzumsande, dergoegge and sipa for suggestions on
how to fix this.
Github-Pull: #30394
Rebased-From: 66673f11 parent fa90989 commit 0933cf5
3 files changed
+16
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
999 | 999 | | |
1000 | 1000 | | |
1001 | 1001 | | |
1002 | | - | |
| 1002 | + | |
1003 | 1003 | | |
1004 | 1004 | | |
1005 | 1005 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
248 | 251 | | |
249 | 252 | | |
250 | 253 | | |
| |||
1576 | 1579 | | |
1577 | 1580 | | |
1578 | 1581 | | |
1579 | | - | |
1580 | | - | |
1581 | | - | |
1582 | 1582 | | |
1583 | 1583 | | |
1584 | 1584 | | |
| |||
5060 | 5060 | | |
5061 | 5061 | | |
5062 | 5062 | | |
| 5063 | + | |
| 5064 | + | |
| 5065 | + | |
| 5066 | + | |
5063 | 5067 | | |
5064 | 5068 | | |
5065 | 5069 | | |
| |||
5548 | 5552 | | |
5549 | 5553 | | |
5550 | 5554 | | |
| 5555 | + | |
| 5556 | + | |
| 5557 | + | |
| 5558 | + | |
| 5559 | + | |
| 5560 | + | |
5551 | 5561 | | |
5552 | 5562 | | |
5553 | 5563 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
0 commit comments