From 525e84b88770be026ca3577669ff5db9aa40dadd Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Fri, 5 Dec 2025 19:03:56 +0100 Subject: [PATCH] archive-index: make wait-time for cache download configurable --- src/config.rs | 6 ++++++ src/storage/mod.rs | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 2f27a9765..c36595cb3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -102,6 +102,8 @@ pub struct Config { // So we can preallocate the DashMap with this number to avoid resizes. pub(crate) local_archive_cache_expected_count: usize, + pub(crate) local_archive_cache_download_wait_ms: u64, + // Where to collect metrics for the metrics initiative. // When empty, we won't collect metrics. pub(crate) compiler_metrics_collection_path: Option, @@ -233,6 +235,10 @@ impl Config { "DOCSRS_ARCHIVE_INDEX_EXPECTED_COUNT", 100_000usize, )?) + .local_archive_cache_download_wait_ms(env( + "DOCSRS_ARCHIVE_INDEX_DOWNLOAD_WAIT_MS", + 1000, + )?) .compiler_metrics_collection_path(maybe_env("DOCSRS_COMPILER_METRICS_PATH")?) .temp_dir(temp_dir) .rustwide_workspace(env( diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 264e07b1b..bbfc94292 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -582,12 +582,11 @@ impl AsyncStorage { // Someone else is already downloading/repairing. Don't queue on write(); just wait // a bit and poll the fast path until it becomes readable or we give up. const STEP_MS: u64 = 10; - const ATTEMPTS: u64 = 50; // = 500ms total wait - const TOTAL_WAIT_MS: u64 = STEP_MS * ATTEMPTS; + let attempts = self.config.local_archive_cache_download_wait_ms / STEP_MS; let mut last_err = None; - for _ in 0..ATTEMPTS { + for _ in 0..attempts { sleep(Duration::from_millis(STEP_MS)).await; match archive_index::find_in_file(local_index_path.clone(), path_in_archive).await { @@ -603,7 +602,8 @@ impl AsyncStorage { Err(last_err .unwrap_or_else(|| anyhow!("archive index unavailable after repair wait")) .context(format!( - "no archive index after waiting for {TOTAL_WAIT_MS}ms" + "no archive index after waiting for {} ms", + self.config.local_archive_cache_download_wait_ms ))) }