Skip to content

Stale Actor State in Reminder callback with Actor Reentrancy Enabled #1615

@dennis-calluy

Description

@dennis-calluy

Expected Behavior

The ReceiveReminderAsync method should access the most current, up-to-date state of the actor, regardless of whether a separate, call had updated the state.

Actual Behavior

When using a Dapr Actor with reentrancy enabled, the actor's state is stale when accessed within a reminder callback. The actor's state is being updated by an external method call, but the reminder's ReceiveReminderAsync method receives only the initial state.

Steps to Reproduce the Problem

Environments:

runtime V1.15.10
dotnet-sdk: v1.15.4

and

runtime V1.16.0-rc.4
dotnet-sdk: v1.16.0-rc15

Enable reentrancy

options.ReentrancyConfig = new ActorReentrancyConfig { Enabled = true, MaxStackDepth = 32 };

After the reminder has started, the ReceiveReminderAsync method will not pick up new state! (STALESTATE is different from ACTUALSTATE after the reminder callback)

async Task IDeviceActor.SetStateAsync(int actualState)
{
    await StateManager.SetStateAsync(ACTUALSTATE, actualState);
    await StateManager.SaveStateAsync();
    Logger.LogInformation($"Actor id {Id}: State set to {actualState}");
}

async Task<(int, int)> IDeviceActor.GetStateAsync()
{
    var deviceState = await StateManager.GetStateAsync<int>(ACTUALSTATE);
    var staleState = await StateManager.TryGetStateAsync<int>(STALESTATE);
    Logger.LogInformation($"Actor id {Id}: Actual state: {deviceState} - Stale (reminder) state: {staleState.Value} ");
    return (deviceState, staleState.Value);
}

async Task IRemindable.ReceiveReminderAsync(string reminderName, byte[] state, TimeSpan dueTime, TimeSpan period)
{
    if (reminderName == REMINDER)
    {
        var reminderState = await StateManager.GetStateAsync<int>(ACTUALSTATE);
        Logger.LogInformation($"Actor id {Id}: Reminder gets state {reminderState}.");

        await StateManager.SetStateAsync(STALESTATE, reminderState);
        await StateManager.SaveStateAsync();
    }
}

Release Note

RELEASE NOTE:

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions