From 8113a8ba12611554e169070706f27c929f97a129 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 13 Oct 2021 12:19:40 -0400 Subject: [PATCH] Don't report the bootstrap as completed unless it actually succeeds. (Previously we'd report it as successful even if the inner download task was a failure.) --- crates/tor-dirmgr/src/bootstrap.rs | 5 ++++- crates/tor-dirmgr/src/lib.rs | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/tor-dirmgr/src/bootstrap.rs b/crates/tor-dirmgr/src/bootstrap.rs index 3f09695c3..81af0f44d 100644 --- a/crates/tor-dirmgr/src/bootstrap.rs +++ b/crates/tor-dirmgr/src/bootstrap.rs @@ -186,7 +186,7 @@ async fn download_attempt( pub(crate) async fn download( dirmgr: Weak>, mut state: Box, - mut on_usable: Option>, + on_usable: &mut Option>, ) -> Result<(Box, Option)> { let runtime = upgrade_weak_ref(&dirmgr)?.runtime.clone(); @@ -277,6 +277,9 @@ pub(crate) async fn download( } // We didn't advance the state, after all the retries. + warn!(n_attempts=retry_config.n_attempts(), + state=%state.describe(), + "Unable to advance downloading state"); return Ok((state, Some(Error::CantAdvanceState))); } } diff --git a/crates/tor-dirmgr/src/lib.rs b/crates/tor-dirmgr/src/lib.rs index c5262746d..8863a5d29 100644 --- a/crates/tor-dirmgr/src/lib.rs +++ b/crates/tor-dirmgr/src/lib.rs @@ -226,11 +226,17 @@ impl DirMgr { })?; if let Some(receiver) = receiver { - let _ = receiver.await; + match receiver.await { + Ok(()) => { + info!("We have enough information to build circuits."); + } + Err(_) => { + warn!("Bootstrapping task exited before finishing."); + return Err(Error::CantAdvanceState.into()); + } + } } - info!("We have enough information to build circuits."); - Ok(dirmgr) } @@ -316,7 +322,7 @@ impl DirMgr { 'retry_attempt: for _ in retry_config.attempts() { let (newstate, recoverable_err) = - bootstrap::download(Weak::clone(&weak), state, on_complete.take()).await?; + bootstrap::download(Weak::clone(&weak), state, &mut on_complete).await?; state = newstate; if let Some(err) = recoverable_err {