Skip to content

Commit

Permalink
Fix retrying crate downloads for network errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Dec 1, 2016
1 parent 80ec9e0 commit df30da0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/cargo/sources/registry/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit df30da0

Please sign in to comment.