ConcurrentDial prematurely gives up on dials
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.6k
- Forks
- 1.3k
- Avg merge
- 8h 47m
- Merged PRs (30d)
- 19
Description
Summary
ConcurrentDial takes a Vec<Dial> and resolves a future with the first address that successfully connects, returning the Multiaddr that was dialed and Ok((PeerId, StreamMuxerBox)) on success. This is wrapped in a task that returns the result to the Pool.
If another peer is listening on that address, the Pool will return PendingOutboundConnectionError::WrongPeerId.
This seems like the multiaddresses are racing to connect, and the first connection is selected regardless of if that address was valid for the dial attempt. The problem is that one of the other addresses in ConcurrentDial might be the address of the correct peer, but at this point we've given up on all other dials and selected the wrong address. So instead of connecting to the correct address, we incorrectly return the WrongPeerId error for the connection that won the race.
Expected behavior
ConcurrentDial should be aware of the PeerId that is being dialed. Connections that would result in a WrongPeerId error should not halt the ConcurrentDial future and should instead continue attempting to establish a valid outgoing connection to the peer we are looking for.
Actual behavior
ConcurrentDial races addresses and will select connections to incorrect peers resolving the future. This results in failing the connection attempt with WrongPeerId.
Relevant log output
Possible Solution
No response
Version
No response
Would you like to work on fixing this bug?
Yes
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in swarm/src/connection/pool/concurrent_dial.rs to trace how competing dials resolve, then read the wrapping flow in swarm/src/connection/pool.rs and swarm/src/connection/pool/task.rs. The fix is complete when a connection producing WrongPeerId does not end ConcurrentDial and a later address for the requested PeerId can succeed without incorrectly returning that error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100