From: Alex Crichton Date: Wed, 30 Nov 2016 00:52:20 +0000 (-0800) Subject: Fix retrying crate downloads for network errors X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~11^2~98^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=df30da0c5702cb5b2fdb0df0d96047e477646366;p=cargo.git Fix retrying crate downloads for network errors Previously the `with_retry` loop was a little too tight where stale state about the sha256 and data was kept out of the loop. Instead we need to reinitialize these on each iteration of the loop to ensure that we correctly retry by forgetting the data we previously downloaded for an aborted download attempt. --- diff --git a/src/cargo/sources/registry/remote.rs b/src/cargo/sources/registry/remote.rs index 480b71859..2b9b1ca02 100644 --- a/src/cargo/sources/registry/remote.rs +++ b/src/cargo/sources/registry/remote.rs @@ -158,17 +158,17 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> { handle.follow_location(true)?; let mut state = Sha256::new(); let mut body = Vec::new(); - { + network::with_retry(self.config, || { + state = Sha256::new(); + body = Vec::new(); let mut handle = handle.transfer(); handle.write_function(|buf| { state.update(buf); body.extend_from_slice(buf); Ok(buf.len()) })?; - network::with_retry(self.config, || { - handle.perform() - })? - } + handle.perform() + })?; let code = handle.response_code()?; if code != 200 && code != 0 { bail!("failed to get 200 response from `{}`, got {}", url, code)