Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The tests lack coverage proving that turn ownership persists through asynchronous state saves and that queued work resumes and locks are cleaned up after both successful and rejected saves.
1 open issue
What changed in this PR
Adds SDK-side actor turn locking to address #930, preventing caller cancellation from allowing another turn to overlap unfinished actor execution and state persistence.
Changes:
- Serializes invocations, reminders, timers, and deactivation per actor while preserving concurrency across distinct actors.
- Passes reentrancy IDs through HTTP dispatch and permits matching chains after activation, with idle lock cleanup.
- Adds concurrency and lifecycle tests, plus documentation of cancellation behavior.
| File | Description |
|---|---|
test/unit/actor/actorTurnLock.test.ts |
Adds serialization, reentrancy, lifecycle, cleanup, and HTTP header tests. |
src/implementation/Server/HTTPServer/actor.ts |
Extracts and forwards reentrancy headers. |
src/actors/runtime/ActorTurnLock.ts |
Implements reference-counted turn locking and waiter handling. |
src/actors/runtime/ActorRuntime.ts |
Forwards optional reentrancy IDs to actor managers. |
src/actors/runtime/ActorManager.ts |
Holds turn leases through actor execution and lifecycle completion. |
src/actors/runtime/AbstractActor.ts |
Documents turn retention after caller cancellation. |
CHANGELOG.md |
Describes the cancellation fix and locking behavior. |
Review effort: Balanced
| res = await actorObject[actorMethodName](args); | ||
| } | ||
|
|
||
| await actorObject.onActorMethodPostInternal(); |
There was a problem hiding this comment.
Added regression tests in f6750d7 with a state-mutating actor and deferred ActorClientHTTP.stateTransaction mocks covering post-method, activation, and deactivation saves across both resolved and rejected transactions (asserting queued invocations and deactivation stay blocked until persistence settles and lock entries drop to 0 afterward).
Keep one turn per actor id until the method and its state save finish. A matching non-empty Dapr-Reentrancy-Id joins that turn after activation, including when the outer activation id is blank or the inner id differs, and reuses the actor already activated for the chain. A call outside that chain with a new non-empty Dapr-Actor-Activation-Id detaches the stale actor before waiting, so the in-flight call cannot save. The stale onDeactivate runs in the next root turn, after the in-flight call releases the lock and before the new onActivate. DELETE unregisters the actor before waiting and can still save unless a newer activation id supersedes it. An empty activation id still does not wait on the sidecar version lookup before the call queues. Fixes dapr#930 Signed-off-by: eisen0419 <usetoken0419@gmail.com>
f6750d7 to
f6e44b0
Compare

Description
When a caller cancels an in-flight actor invocation,
daprdreleases its turn lock and can dispatch the next turn for the same(actorType, actorId)before Node finishes executing the first method and saving state.Following the merged reference implementation in
dapr/dotnet-sdk#1937, this change introduces a reference-counted per-actorActorTurnLockinsideActorManagerso the SDK retains turn ownership until the active invocation (activation, method/reminder/timer callback, post-hook, and state save) finishes.Summary
(actorType, actorId):invoke,fireReminder,fireTimer, anddeactivateacquire the same per-actor turn lock while allowing distinct actor IDs and actor types to execute concurrently.actor.reentrancy.enabled === trueandDapr-Reentrancy-Idis non-empty and matches the active turn's ID can a nested call reenter — and only afteronActivatefinishes (lease.allowReentrancy()). Deactivation ignoresDapr-Reentrancy-Idand waits foractiveCalls === 0.Evidence
daprdreleased its sidecar lock early after caller cancellation and dispatched a second request for the same actor ID while the first call awaited async I/O,ActorManagerexecuted both methods concurrently (maxConcurrent === 2), interleaving actor state mutations.maxConcurrent === 1);npm run buildandnpm run test:unit:allpass (87suites,2,518tests including21new concurrency/reentrancy/exception/cleanup tests intest/unit/actor/actorTurnLock.test.ts).Merge Danger
Door: Two-way
Internal runtime synchronization (
src/actors/runtime/ActorTurnLock.ts,ActorManager.ts,ActorRuntime.ts,HTTPServer/actor.ts) with backward-compatible optionalreentrancyId?: stringparameters and zero new dependencies.Blast Radius: Narrow
Scoped to actor runtime dispatch on the server side; different actor IDs and actor types remain fully concurrent, and outbound client calls are untouched.
Issue reference
Fixes #930
Checklist