Skip to content

Commit df30da0

Browse files
committed
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.
1 parent 80ec9e0 commit df30da0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/cargo/sources/registry/remote.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,17 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
158158
handle.follow_location(true)?;
159159
let mut state = Sha256::new();
160160
let mut body = Vec::new();
161-
{
161+
network::with_retry(self.config, || {
162+
state = Sha256::new();
163+
body = Vec::new();
162164
let mut handle = handle.transfer();
163165
handle.write_function(|buf| {
164166
state.update(buf);
165167
body.extend_from_slice(buf);
166168
Ok(buf.len())
167169
})?;
168-
network::with_retry(self.config, || {
169-
handle.perform()
170-
})?
171-
}
170+
handle.perform()
171+
})?;
172172
let code = handle.response_code()?;
173173
if code != 200 && code != 0 {
174174
bail!("failed to get 200 response from `{}`, got {}", url, code)

0 commit comments

Comments
 (0)