Repository navigation
feat(task): let wait_result retry on result backend errors - #731
Open
Devpaul-01 wants to merge 2 commits into
Open
Devpaul-01 wants to merge 2 commits into
Devpaul-01 wants to merge 2 commits into
Conversation
wait_result() ends the wait on the first ResultIsReadyError, even when the timeout budget is almost untouched. A single Redis read timeout or connection reset says nothing about the task, but callers get a failure for a task that is probably still running or has just finished. Add an opt-in `retry_on_backend_error` argument (default False, so the current fail-fast behaviour is unchanged). When enabled, a failed readiness poll is treated as "not ready yet": - the poll is retried with an exponentially increasing delay, capped at 5s (never below check_interval), so a struggling backend isn't hit at full polling speed; - the delay never extends past the timeout deadline; - on expiry TaskiqResultTimeoutError is raised with the last backend error as its __cause__. Refs taskiq-python#655
A backend blip in the window between "ready" and the actual read raises ResultGetError out of wait_result(), with the same effect as a failed readiness poll: the caller sees a failure for a task that finished fine. When `retry_on_backend_error` is enabled, treat any ResultBackendError raised while checking readiness or fetching the result the same way: retry with backoff until the timeout and chain the last error to TaskiqResultTimeoutError. Refs taskiq-python#655
This branch has not been deployed
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.
Fixes #655
Problem
AsyncTaskiqTask.wait_result()pollsis_ready()and then callsget_result(). AnyResultBackendErrorfrom either call (a Redis read timeout, a connection reset, a failover) propagates straight out ofwait_result(), even when thetimeoutbudget has barely been used. The error says nothing about the task itself, which is usually still running or has just finished, so callers see a failure for work that succeeds.Root cause
wait_result()has no distinction between "the task isn't ready" and "I couldn't ask the backend". Bothis_ready()andget_result()re-raise asResultIsReadyError/ResultGetError, and the polling loop doesn't catch them.Solution
Add an opt-in
retry_on_backend_error: bool = Falseargument towait_result(). The default keeps today's fail-fast behaviour, so this is backwards compatible. When enabled, aResultBackendErrorwhile checking readiness or fetching the result is treated as "not ready yet":check_interval, so a struggling backend isn't polled at full speed;timeoutdeadline;TaskiqResultTimeoutErroris raisedfromthe last backend error, so the underlying failure isn't lost;check_interval.The change is split in two commits: readiness polling first, then
get_result(), so the second can be dropped if you'd rather not retry reads.Tests / verification
AsyncResultBackendthat fails the first N calls: default fail-fast (bothis_readyandget_result), retry then success (both paths), timeout with the last error chained as__cause__, exact backoff sequence, and backoff not overshooting the timeout.master(the argument doesn't exist) and pass with the change; the fail-fast tests pass on both.pytest tests(409 passed).ruff check,ruff format --checkandmypyare clean on the touched files.Open question
With
timeout=-1(no timeout) and the flag enabled, a permanentget_result()error (e.g. a corrupt payload) would be retried forever. That's documented in the docstring since an unbounded wait is already the caller's choice, but if you'd prefer a cap on consecutive failures, or want the second commit dropped, happy to adjust.