Repository navigation
Conversation
…closes dapr#1246) When daprd shuts down or restarts mid-wait (rollouts, pod restarts, runtime reload), the actors router cancels in-flight calls, causing WaitForInstanceCompletion and WaitForInstanceStart to receive grpc.StatusCode.CANCELLED ('context canceled'). Previously, this caused waits to abort and raise RpcError even though the workflow instance was still running on persistent state. - Add grpc.StatusCode.CANCELLED to _TRANSIENT_RPC_CODES in sync and async clients. Callers' timeout deadlines continue to be strictly enforced via _is_deadline_cancellation(), which converts deadline expiration into TimeoutError. - In unbounded wait mode (timeout=0), refresh the 30s transient grace window and reset exponential backoff whenever a healthy in-flight wait was held by daprd before being cancelled, ensuring that long-running workflows survive multiple sidecar restarts. - Update tests from dapr#1112 that previously asserted immediate failure on CANCELLED to verify that server-sent CANCELLED is retried with backoff and succeeds on subsequent re-issue. - Add unit tests verifying multiple sidecar restarts across long waits in both sync and async clients. Fixes dapr#1246 Signed-off-by: NaniToka <tokananiy@gmail.com>
|
Claude review · not a review sign-off.
Minor
Reviewed at bcddae9. |
…ocally Signed-off-by: NaniToka <tokananiy@gmail.com>
|
Thanks for the thorough review and catch @CasperGN! You're completely right — when the client or underlying channel is closed locally during an in-flight wait, retrying on the terminated channel caused gRPC to raise Pushed a fix in
|
CasperGN
left a comment
There was a problem hiding this comment.
Thanks @NaniToka for picking up #1246 and for your interest in the project! 🙌 Retrying a server-sent CANCELLED only while the caller still has time left, and still turning a cancellation at the deadline into TimeoutError, is what the issue asked for. Stopping right away once the client is closed locally is a nice touch, and the in-flight close tests cover it well 🧪. I left a few comments inline, please take a look.
A few more notes:
- Only the DCO check is reported on this head commit so far, so the build and test workflows still need to run before this can merge.
- The PR also adds public API that the description doesn't mention:
is_closedon bothDaprWorkflowClients, plusaclose(),close()andasync withsupport on the async one. Could you list these in the description so they show up in the release notes?
Drafted with AI assistance and reviewed by me.
| # before being cancelled by a new restart, restart the grace | ||
| # window and reset backoff rather than anchoring on the first error. | ||
| if unbounded: | ||
| if code == grpc.StatusCode.CANCELLED and call_duration >= 1.0: |
There was a problem hiding this comment.
With an unbounded wait, any CANCELLED that took at least 1s clears transient_deadline, so nothing caps how many times we retry. If something between the client and daprd always cancels after a second or more (a proxy idle timeout, an interceptor, a daprd stuck in a restart loop), wait_for_orchestration_completion(timeout=0) keeps retrying forever, logging only warnings. Before this change, the 30s window always ended in an error. What do you think about capping the number of resets in a row (or the total time spent retrying), or at least logging at a higher level when the window resets? A test where every attempt is CANCELLED after more than 1s would pin down whichever behaviour we choose. The same applies to the async client at aio/client.py line 324.
There was a problem hiding this comment.
Really sharp catch on the unbounded wait loop when a proxy or restart cycle keeps cancelling.
I went with capping consecutive in-flight resets: added _MAX_CONSECUTIVE_TRANSIENT_RESETS = 3 to both sync and async clients. If cancellations keep arriving after >=1s, the 30s grace window is refreshed up to 3 times (with a warning log showing the count). Once the cap is reached, the window no longer extends, allowing persistent failure modes to surface the real RpcError instead of spinning forever.
Added regression tests in test_orchestration_wait.py and test_client_async.py verifying that continuous in-flight cancellations eventually propagate.
| return WorkflowRerunResult(new_instance_id=res.newInstanceID, staged=res.staged) | ||
|
|
||
| @property | ||
| def is_closed(self) -> bool: |
There was a problem hiding this comment.
This adds is_closed, aclose(), close() and __aenter__/__aexit__ to the public async DaprWorkflowClient (and is_closed to the sync one), but the new tests only cover the _durabletask clients. Could you add a small test that async with DaprWorkflowClient(...) closes the inner client and that is_closed reflects it? These will be public API once released, so a test keeps them from regressing.
There was a problem hiding this comment.
Definitely — added tests covering is_closed, close(), aclose(), and context managers (with and async with) across test_workflow_client.py and test_workflow_client_aio.py.
I also added __enter__ / __exit__ to the sync DaprWorkflowClient so both sync and async clients share the same context manager ergonomics.
| raise | ||
|
|
||
| now = time.monotonic() | ||
| call_duration = time.perf_counter() - call_start |
There was a problem hiding this comment.
nit: call_duration uses time.perf_counter(), while every other timing in this loop uses time.monotonic(). Using time.monotonic() for call_start as well would keep one clock here and mean tests only need to patch one function. The same goes for the async client.
There was a problem hiding this comment.
Good spot! Switched call_start to time.monotonic() and compute call_duration = now - call_start directly. Much cleaner to stick to a single clock, and it let us drop the extra perf_counter mock from the test suite as well.
…add public client tests - Cap consecutive transient grace window resets in unbounded wait mode (_MAX_CONSECUTIVE_TRANSIENT_RESETS = 3) for both sync and async clients, preventing persistent proxy/sidecar cancellation loops from retrying indefinitely. - Log warning with reset counter and warning on reset cap exhaustion. - Use time.monotonic() consistently for call_start and call_duration in both sync and async retry loops, eliminating time.perf_counter(). - Add context manager (__enter__/__exit__) to sync DaprWorkflowClient. - Add unit tests for public DaprWorkflowClient lifecycle (is_closed, close, aclose, and context managers in sync and async). - Add regression tests verifying consecutive in-flight cancellations are capped and eventually propagate grpc.RpcError(StatusCode.CANCELLED). Signed-off-by: NaniToka <tokananiy@gmail.com>
|
Thanks for the thorough follow-up review, @CasperGN! Pushed commit
Whenever you get a chance, could you trigger the CI test workflow on this commit? Thanks again for helping steer the design! |
CasperGN
left a comment
There was a problem hiding this comment.
Round 3 of 3: follow-up on the changes since 8260cf1.
Every earlier blocker is resolved and the new changes add none.
Nits, not blocking:
- F1: Grace-window refresh only applies to CANCELLED, so a later restart that surfaces as UNAVAILABLE/FAILED_PRECONDITION after a long healthy wait is raised immediately against the stale transient_deadline (
dapr/ext/workflow/_durabletask/client.py) - F2: Mixes perf_counter with monotonic and hardcodes the 1.0s healthy-wait threshold in both clients (
dapr/ext/workflow/_durabletask/client.py)
Drafted with AI assistance and reviewed by me.
|
Thanks so much for the thorough review and guidance throughout this, @CasperGN! Really appreciate your help in steering the design. Made a note of the non-blocking nits on the grace window and threshold constants for follow-up improvements down the road. Whenever you have a moment to trigger the CI run, it should be all set to go! 🙌 |
Description
Implements the proposal in #1246 by @CasperGN: re-issue
WaitForInstanceCompletionandWaitForInstanceStart(sync and async) when the server ends the wait call withgrpc.StatusCode.CANCELLEDand the caller's timeout has not expired.Problem
When
daprdshuts down or restarts mid-wait (e.g. rollouts, pod restarts, runtime reload), the actors router cancels all in-flight calls it tracks (dapr/dapr#10566). Previously, this causedwait_for_orchestration_completionandwait_for_orchestration_startto abort and raisegrpc.RpcError(StatusCode.CANCELLED)immediately, even though the workflow is intact and running on durable storage.Solution
CANCELLEDto_TRANSIENT_RPC_CODES:grpc.StatusCode.CANCELLEDto_TRANSIENT_RPC_CODESin bothTaskHubGrpcClient(dapr/ext/workflow/_durabletask/client.py) andAsyncTaskHubGrpcClient(dapr/ext/workflow/_durabletask/aio/client.py)._is_deadline_cancellation()maps deadline expiration to_TransientTimeout(TimeoutError), ensuring that caller-specified deadlines are never exceeded.timeout=0), when a healthy wait was in-flight and held bydaprdbefore being cancelled by a restart,transient_deadlineand backoff are refreshed, capped at_MAX_CONSECUTIVE_TRANSIENT_RESETS = 3to prevent infinite loops from persistent proxy idle timeouts or sidecar crash loops.CANCELLEDis re-raised immediately without retrying or invoking calls on the closed channel.is_closedproperty to both sync and asyncDaprWorkflowClient(and underlyingTaskHubGrpcClient/AsyncTaskHubGrpcClient) to inspect channel closure status.close(),aclose(), and async context manager (async with) support todapr.ext.workflow.aio.DaprWorkflowClient.with) support todapr.ext.workflow.DaprWorkflowClient.test_cancelled_within_deadline_still_propagates,test_cancelled_unbounded_wait_still_propagatesin sync and async) to verify thatCANCELLEDis absorbed, retried with backoff, and succeeds when the subsequent wait call returns the workflow state.grpc.RpcErroronce the grace window or consecutive reset cap elapses.is_closedand avoids re-invoking on closed channels.is_closed,close(),aclose(), and context manager lifecycles across sync and async publicDaprWorkflowClients.Issue reference
Please reference the issue this PR will close: Closes #1246
Checklist