镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Possible error in usage of cancellationToken parameter to context.CreateTimer in AzureStorageScenarioTests.cs? #1178

Open

Description

Referring to

https://github.com/Azure/durabletask/blob/main/test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs#L3151, which is:

 Task timeoutTask = context.CreateTimer(deadline, cts.Token);

The second parameter of context.CreateTimer, that should be the state, not the cancellationToken, am I right? I'm trying to understand how to use this in my own projects, and looking at the source code to understand.

In this particular scenario, the state returned from the CreateTimer is not used, so it might not be easy to spot, but shouldn't the line be:

 object dummyState = new object() // whatever, the result is not used in this example
 Task timeoutTask = context.CreateTimer(deadline, dummyState, cts.Token);

where dummyState is the state? If not, the timer will never be cancelled, even when the approval task completes, and the orchestration instance will never finish?

Or have I misunderstood how this works?

Activity

  1. cgillum commented on Jan 6, 2025

    @cgillum
    Member

    I think you're right. In fact, passing a cancellation token as the state parameter can be quite dangerous since deserializing cancellation tokens can result in memory corruption. We'll look into fixing this test code and maybe adding a runtime check for this mistake. Thanks for bringing this up.

  2. erikbra commented on Jan 6, 2025

    @erikbra
    Author

    Nice, thanks a lot for your input! It aligns with what I see in my own code too. The timer never gets cancelled, even if I cancel the CancellationTokenSource, if I use it as in the example. However, if I pass a(ny) state as the 2nd parameter, and the cancellation token as the last parameter, things work as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions