From 5e544a687a2ed6a07ad7932c487dfaf47e2fbc02 Mon Sep 17 00:00:00 2001 From: halspang <70976921+halspang@users.noreply.github.com> Date: Thu, 22 Jul 2021 22:28:36 +0000 Subject: [PATCH] Only isolate state when using reentrancy (#723) Non-reentrant actors can utilize their state manager's cache for repeated calls. They should still be able to do this unless using reentrancy. Co-authored-by: Ryan Nowak --- src/Dapr.Actors/Runtime/ActorManager.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Dapr.Actors/Runtime/ActorManager.cs b/src/Dapr.Actors/Runtime/ActorManager.cs index 17cc838a3..e7f068635 100644 --- a/src/Dapr.Actors/Runtime/ActorManager.cs +++ b/src/Dapr.Actors/Runtime/ActorManager.cs @@ -339,10 +339,13 @@ private async Task DispatchInternalAsync(ActorId actorId, ActorMethodConte T retval; try { - // Set the state context of the request, if possible. - if (state.Actor.StateManager is IActorContextualState contextualStateManager) + // Set the state context of the request, if required and possible. + if (ActorReentrancyContextAccessor.ReentrancyContext != null) { - await contextualStateManager.SetStateContext(Guid.NewGuid().ToString()); + if (state.Actor.StateManager is IActorContextualState contextualStateManager) + { + await contextualStateManager.SetStateContext(Guid.NewGuid().ToString()); + } } // invoke the function of the actor