From 987359f19ac381b8b1cdcb6baee4cc196181b588 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Wed, 18 Sep 2019 14:47:07 +0100 Subject: [PATCH] backtracking: Limit backtracking via env var Use RUSTUP_BACKTRACK_LIMIT (default 60) to limit the backtrack attempts when trying to find a valid nightly to install. Signed-off-by: Daniel Silverstone --- README.md | 4 ++++ src/dist/dist.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 478b9eab82c..4f5fa918799 100644 --- a/README.md +++ b/README.md @@ -637,6 +637,10 @@ Command | Description - `RUSTUP_UNPACK_RAM` *unstable* (default 400M, min 100M) Caps the amount of RAM rustup will use for IO tasks while unpacking. +- `RUSTUP_BACKTRACK_LIMIT` *unstable* (default 60, min 1) + Caps the number of days that rustup will backtrack when looking for a nightly + which suits the user's installation. + - `RUSTUP_NO_BACKTRACE` Disables backtraces on non-panic errors even when `RUST_BACKTRACE` is set. diff --git a/src/dist/dist.rs b/src/dist/dist.rs index 5d7dc20a71f..f4573a9da9b 100644 --- a/src/dist/dist.rs +++ b/src/dist/dist.rs @@ -605,6 +605,11 @@ fn update_from_dist_<'a>( let mut fetched = String::new(); let mut first_err = None; let backtrack = toolchain.channel == "nightly" && toolchain.date.is_none(); + let mut backtrack_attempts: i32 = env::var("RUSTUP_BACKTRACK_LIMIT") + .ok() + .unwrap_or_else(|| "60".to_string()) + .parse() + .map_err(|e| format!("Bad number for RUSTUP_BACKTRACK_LIMIT: {}", e))?; loop { match try_update_from_dist_( download, @@ -640,6 +645,17 @@ fn update_from_dist_<'a>( break Err(e); } + backtrack_attempts -= 1; + if backtrack_attempts < 1 { + if let Some(e) = first_err { + break Err(e); + } else { + break Err(Error::from(ErrorKind::MissingReleaseForToolchain( + toolchain.channel, + ))); + } + } + // The user asked to update their nightly, but the latest nightly does not have all // the components that the user currently has installed. Let's try the previous // nightlies in reverse chronological order until we find a nightly that does,