Skip to content

bug: Dapr.Actors: Cancellation doesn't block turns on subseqeuent actor invocations - #1937

Merged
WhitWaldo merged 4 commits into
masterfrom
actors-bad-turns
Oct 18, 2026
Merged

WhitWaldo merged 4 commits into
masterfrom
actors-bad-turns

Conversation

@WhitWaldo

@WhitWaldo WhitWaldo commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

@olitomlinson raised an observation that if a request was made to an actor instance and then the call cancelled while in flight, a second request will start executing its turn in the actor while the first call is still running breaking the actor turn guarantee. This applies an SDK-level lock to prevent this from occurring.

That said, this is something that should really be fixed on the runtime itself. It does not support in-flight cancellation to my knowledge, but it should also not send the SDK the second message without confirmation that the first call had completed one way or the other.

Regardless, this PR patches this behavior in lieu of explicit runtime support as this fix applies assumptions about the actor turn model.

In an abundance of caution about introducing reentrancy and concurrency errors, I've also added a small collection of new integration tests to validate this doesn't introduce regressions.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #[issue number]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

…are cancelled

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
…egressions

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
@WhitWaldo WhitWaldo added this to the v1.19 milestone Oct 18, 2026
@WhitWaldo WhitWaldo self-assigned this Oct 18, 2026
@WhitWaldo
WhitWaldo requested review from a team as code owners October 18, 2026 03:23
@WhitWaldo WhitWaldo added kind/bug Something isn't working area/actor/client labels Oct 18, 2026
@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.97%. Comparing base (b0da611) to head (768b800).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1937      +/-   ##
==========================================
+ Coverage   65.19%   65.97%   +0.77%     
==========================================
  Files         370      371       +1     
  Lines       10766    10854      +88     
  Branches     1262     1273      +11     
==========================================
+ Hits         7019     7161     +142     
+ Misses       3409     3355      -54     
  Partials      338      338              
Flag Coverage Δ
net10.0 65.95% <100.00%> (+0.79%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

olitomlinson added a commit to olitomlinson/dapr-mq that referenced this pull request Oct 18, 2026
When a caller cancels actor calls queued behind a running turn, the Dapr
sidecar dispatches them to the app about 50ms later, while that turn is still
executing (dapr/dapr#10835, reproduced in
github.com/olitomlinson/dapr-actor-concurrency-repro). On the queue actor,
concurrent turns overwrote each other's state: LockCount drifted from the lock
rows by thousands and "Count desync" dropped the queue's priority metadata.

ActorTurnGuard restores one turn at a time per actor inside the actor host,
modelled on the SDK-side fix in dapr/dotnet-sdk#1937. Middleware wraps every
request the sidecar sends to /actors/{type}/{id}/... and holds the turn until
the SDK has finished it, state save and response included. A call in the same
reentrancy chain may enter; a call whose request is aborted while it waits is
dropped without running. Each time it has to step in it logs a warning naming
the issue.

TEMPORARY: remove it once the runtime or the SDK ships a fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WhitWaldo
WhitWaldo merged commit 00d1b65 into master Oct 18, 2026
393 checks passed
@WhitWaldo
WhitWaldo deleted the actors-bad-turns branch October 18, 2026 15:49
olitomlinson added a commit to olitomlinson/dapr-mq that referenced this pull request Oct 26, 2026
…verlap

The guard (#77) held one turn per actor in the host because callers
cancelling queued calls made the sidecar start them while a turn was in
progress (dapr/dapr#10835).

The runtime fix in 1.19.0 (dapr/dapr#10842) narrows this but doesn't close
it: the standalone repro on runtime 1.19.0 with Dapr.Actors 1.18.10 still
overlapped in 3 of 12 cancellation trials with reentrancy off and 4 of 12
with it on. The SDK's own turn lock (dapr/dotnet-sdk#1937, in
Dapr.Actors 1.19.0) closes it: on runtime and SDK 1.19.0, 0 of 24 trials
overlapped. So the guard goes with this upgrade, and Dapr.Actors must stay
at 1.19.0 or later.

- Program.cs no longer adds the middleware; ActorTurnGuard.cs and its tests
  are deleted.
- The issue document moves to docs/issues/resolved/ with the results above.
- ADR 0003 and two proposals no longer describe the guard as current.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
olitomlinson added a commit to olitomlinson/dapr-mq that referenced this pull request Oct 26, 2026
…verlap

The guard (#77) held one turn per actor in the host because callers
cancelling queued calls made the sidecar start them while a turn was in
progress (dapr/dapr#10835).

The runtime fix in 1.19.0 (dapr/dapr#10842) narrows this but doesn't close
it: the standalone repro on runtime 1.19.0 with Dapr.Actors 1.18.10 still
overlapped in 3 of 12 cancellation trials with reentrancy off and 4 of 12
with it on. The SDK's own turn lock (dapr/dotnet-sdk#1937, in
Dapr.Actors 1.19.0) closes it: on runtime and SDK 1.19.0, 0 of 24 trials
overlapped. So the guard goes with this upgrade, and Dapr.Actors must stay
at 1.19.0 or later.

- Program.cs no longer adds the middleware; ActorTurnGuard.cs and its tests
  are deleted.
- The issue document moves to docs/issues/resolved/ with the results above.
- ADR 0003 and two proposals no longer describe the guard as current.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/actor/client kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant