Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: better retry tracing #6836

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crates/common/src/provider/tower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ impl Service<RequestPacket> for RetryBackoffService<RuntimeTransport> {
if rate_limit_retry_number > this.max_rate_limit_retries {
return Err(TransportErrorKind::custom_str("Max retries exceeded"))
}
trace!("retrying request due to {:?}", err);

let current_queued_reqs = this.requests_enqueued.load(Ordering::SeqCst) as u64;

// try to extract the requested backoff from the error or compute the next
// backoff based on retry count
let mut next_backoff = this
.policy
.backoff_hint(&err)
let backoff_hint = this.policy.backoff_hint(&err);
let next_backoff = backoff_hint
.unwrap_or_else(|| std::time::Duration::from_millis(this.initial_backoff));

// requests are usually weighted and can vary from 10 CU to several 100 CU,
Expand All @@ -151,10 +151,12 @@ impl Service<RequestPacket> for RetryBackoffService<RuntimeTransport> {
current_queued_reqs,
ahead_in_queue,
);
next_backoff +=
let total_backoff = next_backoff +
std::time::Duration::from_secs(seconds_to_wait_for_compute_budget);

tokio::time::sleep(next_backoff).await;
trace!(?total_backoff, budget_backoff = ?seconds_to_wait_for_compute_budget, default_backoff = ?next_backoff, ?backoff_hint, "backing off due to rate limit");

tokio::time::sleep(total_backoff).await;
} else {
if timeout_retries < this.max_timeout_retries {
timeout_retries += 1;
Expand Down