From df30da0c5702cb5b2fdb0df0d96047e477646366 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 29 Nov 2016 16:52:20 -0800 Subject: [PATCH] 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. --- src/cargo/sources/registry/remote.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cargo/sources/registry/remote.rs b/src/cargo/sources/registry/remote.rs index 480b7185950..2b9b1ca02dd 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)