Skip to content

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FranciscoTGouveia
Copy link
Contributor

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.

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(),
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.
Copy link
Contributor

@djc djc left a 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!

Comment on lines +637 to +654
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();
Copy link
Contributor

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Download TimedOut on company firewall
3 participants