Skip to content

Commit

Permalink
fix(net): do not dial regions in parallel (#1736)
Browse files Browse the repository at this point in the history
These are supposed to be dialed in order, not in parallel.

This should also fix the warnings in the logs about aborted dials.
  • Loading branch information
dignifiedquire committed Oct 26, 2023
1 parent d44a7dc commit c851fe1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 35 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion iroh-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ rust-version = "1.72"
aead = { version = "0.5.2", features = ["bytes"] }
anyhow = { version = "1", features = ["backtrace"] }
backoff = "0.4.0"
bounded_join_set = "0.1.0"
bytes = "1"
crypto_box = { version = "0.9.1", features = ["serde", "chacha20"] }
curve25519-dalek = "4.0.0"
Expand Down
32 changes: 8 additions & 24 deletions iroh-net/src/derp/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,40 +1056,24 @@ impl Actor {
&self,
reg: DerpRegion,
) -> Result<(TcpStream, Arc<DerpNode>), ClientError> {
debug!("dial region: {:?}", reg);
trace!(?reg, "dialing region");
let target = self.target_string(&reg);
if reg.nodes.is_empty() {
return Err(ClientError::NoNodeForTarget(target));
}
// usually 1 IPv4, 1 IPv6 and 2x http
const DIAL_PARALLELISM: usize = 4;
let mut dials = bounded_join_set::JoinSet::new(DIAL_PARALLELISM);

let prefer_ipv6 = self.prefer_ipv6().await;

let mut errs = Vec::new();
for node in reg.nodes.clone().into_iter() {
let target = target.clone();
dials.spawn(async move {
if node.stun_only {
return Err(ClientError::StunOnlyNodesFound(target));
}

dial_node(&node, prefer_ipv6).await.map(|c| (c, node))
});
}
if node.stun_only {
return Err(ClientError::StunOnlyNodesFound(target.clone()));
}

let mut errs = Vec::new();
while let Some(res) = dials.join_next().await {
match res {
Ok(Ok((conn, node))) => {
// return on the first successfull one
trace!("dialed region");
return Ok((conn, node));
match dial_node(&node, prefer_ipv6).await {
Ok(conn) => {
return Ok((conn, node.clone()));
}
Err(e) => {
errs.push(ClientError::DialTask(e));
}
Ok(Err(e)) => {
errs.push(e);
}
}
Expand Down

0 comments on commit c851fe1

Please sign in to comment.