Skip to content

Commit 6e6b97e

Browse files
fix(iroh-net): better logic for initial derp connection
- avoid double derp connection - do not block on establishing the derp connection
1 parent 9944eb8 commit 6e6b97e

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

iroh-net/src/hp/magicsock/derp_actor.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,21 @@ impl DerpActor {
360360
reader: ReaderState::new(region_id, cancel, dc.clone()),
361361
};
362362

363-
// Make sure we can establish a connection.
364-
if let Err(err) = dc.connect().await {
365-
// TODO: what to do?
366-
warn!("failed to connect to derp server: {:?}", err);
367-
}
368-
363+
// Insert, to make sure we do not attempt to double connect.
369364
self.active_derp.insert(region_id, ad);
370365

366+
// Kickoff a connection establishment in the background
367+
let dc_spawn = dc.clone();
368+
tokio::task::spawn(async move {
369+
// Make sure we can establish a connection.
370+
if let Err(err) = dc_spawn.connect().await {
371+
// TODO: what to do?
372+
warn!("failed to connect to derp server: {:?}", err);
373+
}
374+
});
375+
371376
inc!(MagicsockMetrics, num_derp_conns_added);
377+
372378
self.log_active_derp();
373379

374380
if let Some(ref f) = self.conn.on_derp_active {

0 commit comments

Comments
 (0)