Skip to content

Commit dd69674

Browse files
committed
fix(publish): Check remote git registry more than once post-publish
With `publish-timeout` on remote git registries, we were checking once and never checking again. There were 3 layers of guards preventing the cache from being updating - `needs_update`, handled via `invalidate_cache` - `config.updated_sources()`,. handled by removing from the HashSet - `updated`, inaccessible This change collapses `updated` into `config.updated_sources()`, allowing the cache to be updated Tested by publishing `epage-publish-test`. After about 7 registry updates, it succeded. Before, it just hit the timeout of 60s. No tests are added as we don't have the plumbing setup to be able to control when the test remote git registry publishes. All of our tests focus on the remote http registry. Fixes #11253
1 parent 3ff0443 commit dd69674

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/cargo/sources/registry/remote.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ pub struct RemoteRegistry<'cfg> {
3232
head: Cell<Option<git2::Oid>>,
3333
current_sha: Cell<Option<InternedString>>,
3434
needs_update: bool, // Does this registry need to be updated?
35-
updated: bool, // Has this registry been updated this session?
3635
}
3736

3837
impl<'cfg> RemoteRegistry<'cfg> {
@@ -49,7 +48,6 @@ impl<'cfg> RemoteRegistry<'cfg> {
4948
head: Cell::new(None),
5049
current_sha: Cell::new(None),
5150
needs_update: false,
52-
updated: false,
5351
}
5452
}
5553

@@ -141,6 +139,14 @@ impl<'cfg> RemoteRegistry<'cfg> {
141139
self.current_sha.set(Some(sha));
142140
Some(sha)
143141
}
142+
143+
fn is_updated(&self) -> bool {
144+
self.config.updated_sources().contains(&self.source_id)
145+
}
146+
147+
fn mark_updated(&self) {
148+
self.config.updated_sources().insert(self.source_id);
149+
}
144150
}
145151

146152
const LAST_UPDATED_FILE: &str = ".last-updated";
@@ -214,7 +220,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
214220

215221
match load_helper(&self, path, index_version) {
216222
Ok(result) => Poll::Ready(Ok(result)),
217-
Err(_) if !self.updated => {
223+
Err(_) if !self.is_updated() => {
218224
// If git returns an error and we haven't updated the repo, return
219225
// pending to allow an update to try again.
220226
self.needs_update = true;
@@ -250,19 +256,20 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
250256
return Ok(());
251257
}
252258

253-
self.updated = true;
254259
self.needs_update = false;
255260

256-
if self.config.offline() {
261+
// Make sure the index is only updated once per session since it is an
262+
// expensive operation. This generally only happens when the resolver
263+
// is run multiple times, such as during `cargo publish`.
264+
if self.is_updated() {
257265
return Ok(());
258266
}
259-
if self.config.cli_unstable().no_index_update {
267+
self.mark_updated();
268+
269+
if self.config.offline() {
260270
return Ok(());
261271
}
262-
// Make sure the index is only updated once per session since it is an
263-
// expensive operation. This generally only happens when the resolver
264-
// is run multiple times, such as during `cargo publish`.
265-
if self.config.updated_sources().contains(&self.source_id) {
272+
if self.config.cli_unstable().no_index_update {
266273
return Ok(());
267274
}
268275

@@ -291,7 +298,6 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
291298
let repo = self.repo.borrow_mut().unwrap();
292299
git::fetch(repo, url.as_str(), &self.index_git_ref, self.config)
293300
.with_context(|| format!("failed to fetch `{}`", url))?;
294-
self.config.updated_sources().insert(self.source_id);
295301

296302
// Create a dummy file to record the mtime for when we updated the
297303
// index.
@@ -301,13 +307,12 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
301307
}
302308

303309
fn invalidate_cache(&mut self) {
304-
if !self.updated {
305-
self.needs_update = true;
306-
}
310+
// To fully invalidate, undo `mark_updated`s work
311+
self.needs_update = true;
307312
}
308313

309314
fn is_updated(&self) -> bool {
310-
self.updated
315+
self.is_updated()
311316
}
312317

313318
fn download(&mut self, pkg: PackageId, checksum: &str) -> CargoResult<MaybeLock> {

0 commit comments

Comments
 (0)