Repository navigation
fix(rate_limit): don't block the executor thread while waiting to retry - #130
Merged
AntoniosBarotsis merged 1 commit intoNov 14, 2026
Merged
Conversation
send_with_retry_opts slept with std::thread::sleep inside an async fn, which stalls every other task on the same runtime thread during a rate-limit backoff. Use futures_timer::Delay (already in the tree via governor) instead. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
send_with_retry_opts(andretry!/retry_opts!) waited between retries withstd::thread::sleepinside anasync fn. On a single-threaded runtime (or whenever worker threads are saturated) that stalls every other task for the whole backoff, which is at least 1 s by default andratelimit_resetseconds when the API sends it.Fix. Wait with
futures_timer::Delay, which is runtime-agnostic (the crate does not depend on tokio outside dev-dependencies) and is already in the dependency tree throughgovernor. Added a CHANGELOG entry under Unreleased.Test.
rate_limit::test::test_retry_does_not_block_executorruns the retry next to a ticker task on acurrent_threadruntime and asserts the ticker made progress before the retry fired (red before: the ticker never ran during the sleep).Reproduction
retry_opts!on a call that returnsError::RateLimit, joined with any other task on#[tokio::main(flavor = "current_thread")]: the other task does not run until the backoff ends.This PR was prepared with the assistance of an AI tool (Claude Code).
Summary by cubic
Stops
send_with_retry_opts(and theretry!/retry_opts!macros) from blocking the executor thread between retries. Previously the backoff usedstd::thread::sleepin an async context, which stalled every other task on single-threaded runtimes for the full wait duration. It now awaitsfutures_timer::Delayinstead, which is runtime-agnostic and already in the dependency tree viagovernor.Tests
test_retry_does_not_block_executor, which runs a retry alongside a ticker task on acurrent_threadruntime and asserts the ticker makes progress while the retry waits.Written for commit 63d6385. Summary will update on new commits.