Skip to content

Commit

Permalink
apply external cooldown only upon error
Browse files Browse the repository at this point in the history
  • Loading branch information
saketh-are committed Nov 24, 2024
1 parent d11323c commit 51eec8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
1 change: 0 additions & 1 deletion chain/client/src/sync/state/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ impl StateSyncDownloader {
loop {
match attempt().await {
Ok(header) => {
tracing::debug!(target: "state_sync", "Acquired state header for shard {}", shard_id);
return Ok(header);
}
Err(err) => {
Expand Down
19 changes: 9 additions & 10 deletions chain/client/src/sync/state/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@ impl StateSyncDownloadSourceExternal {
Err(near_chain::Error::Other("Cancelled".to_owned()))
}
result = fut => {
// A download error typically indicates that the file is not available yet. At the
// start of the epoch it takes a while for dumpers to populate the external storage
// with state files. This backoff period prevents spamming requests during that time.
let deadline = clock.now() + backoff;
tokio::select! {
_ = clock.sleep_until(deadline) => {}
_ = cancellation.cancelled() => {}
}

result.map_err(|e| {
// A download error typically indicates that the file is not available yet. At the
// start of the epoch it takes a while for dumpers to populate the external storage
// with state files. This backoff period prevents spamming requests during that time.
let deadline = clock.now() + backoff;
tokio::select! {
_ = clock.sleep_until(deadline) => {}
_ = cancellation.cancelled() => {}
}

increment_download_count(shard_id, typ, "external", "download_error");
tracing::debug!(target: "sync", "Failed to download with error {}", e);
near_chain::Error::Other(format!("Failed to download: {}", e))
})
}
Expand Down

0 comments on commit 51eec8c

Please sign in to comment.