diff --git a/src/context.rs b/src/context.rs index ecbf74c06c..b9acab38c7 100644 --- a/src/context.rs +++ b/src/context.rs @@ -485,21 +485,20 @@ impl Context { /// Stops the IO scheduler. pub async fn stop_io(&self) { + self.scheduler.stop(self).await; if let Some(iroh) = self.iroh.write().await.take() { // Close all QUIC connections. - let ctx = self.clone(); // Spawn into a separate task, // because Iroh calls `wait_idle()` internally // and it may take time, especially if the network // has become unavailable. tokio::spawn(async move { - if let Err(err) = iroh.close().await { - warn!(ctx, "Failed to close Iroh: {err:#}."); - } + // We do not log the error because we do not want the task + // to hold the reference to Context. + let _ = tokio::time::timeout(Duration::from_secs(60), iroh.close()).await; }); } - self.scheduler.stop(self).await; } /// Restarts the IO scheduler if it was running before