-
Notifications
You must be signed in to change notification settings - Fork 967
Introduce RUSTUP_DOWNLOAD_TIMEOUT
to override the download timeout
#4440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Introduce RUSTUP_DOWNLOAD_TIMEOUT
to override the download timeout
#4440
Conversation
src/download/mod.rs
Outdated
let timeout = Duration::from_secs(match process.var("RUSTUP_DOWNLOAD_TIMEOUT") { | ||
Ok(s) => s.parse::<NonZeroU64>().context( | ||
"invalid value in RUSTUP_DOWNLOAD_TIMEOUT -- must be a natural number greater than zero", | ||
).unwrap().get(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using an .unwrap()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get the NonZeroU64
out of the Result
; but after reading about good practices, I realized that using ?
instead of .unwrap()
is preferable.
Is this what you were referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, IMO it's nicer to write NonZeroU64::from_str(s)
compared to s.parse::<NonZeroU64>()
.
…ding download timeout As some (corporate) firewalls take too much time to verify the downloads, the timeout is reached and the user cannot complete its installation. Besides changing the timeout from 30 secs to 3 mins, a new environment variable is introduced to allow users to override the timeout value to their taste.
bf699dd
to
d19ffb2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see that you are now passing Duration
by value!
pub(super) fn native_tls_client(timeout: Duration) -> Result<&'static Client, DownloadError> { | ||
if let Some(client) = CLIENT_NATIVE_TLS.get() { | ||
return Ok(client); | ||
} | ||
|
||
// woah, an unwrap?! | ||
// It's OK. This is the same as what is happening in curl. | ||
// | ||
// The curl::Easy::new() internally assert!s that the initialized | ||
// Easy is not null. Inside reqwest, the errors here would be from | ||
// the TLS library returning a null pointer as well. | ||
catcher().unwrap() | ||
}); | ||
let client = client_generic() | ||
.read_timeout(timeout) | ||
.user_agent(super::REQWEST_DEFAULT_TLS_USER_AGENT) | ||
.build() | ||
.map_err(DownloadError::Reqwest)?; | ||
|
||
let _ = CLIENT_NATIVE_TLS.set(client); | ||
|
||
Ok(CLIENT_NATIVE_TLS.get().unwrap()) | ||
} | ||
|
||
#[cfg(feature = "reqwest-native-tls")] | ||
static CLIENT_NATIVE_TLS: OnceLock<Client> = OnceLock::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from LazyLock
to OnceLock
seems unrelated and doesn't look like an improvement to me.
@@ -66,6 +66,9 @@ | |||
|
|||
- `RUSTUP_TERM_WIDTH` (default: none). Allows to override the terminal width for progress bars. | |||
|
|||
- `RUSTUP_DOWNLOAD_TIMEOUT` (default: 180). Allows to override the default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: You probably need to mark this variable as unstable.
Fixes #4439.
Besides increasing the default timeout from 30 seconds to 3 minutes, a new environment variable (
RUSTUP_DOWNLOAD_TIMEOUT
) is introduced to allow users to override this value.