question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WaitForOrchestrationAsync gets stuck in Running even though it finished?

See original GitHub issue

Hi. I am trying to evaluate DTF to replace an in-house distributed task implementation, and while its looking great, I am having what seems to be a fairly fundamental issue (so probably I am doing something wrong 😉.

What I am seeing is that orchestrations execute just fine, but stay stuck in “Running” state. I have included a small example below. In this particular example, the “Done waiting” message is printed, but WaitForOrchestrationAsync never ends (and if I change the code to poll the state, it stays in “Running”. If I remove the await inside the orchestration it works fine but that is kind of the whole point of DTF 😃

This simple example is derived from a bigger example with the same problems (where the orchestration is only await’ing scheduled tasks).

var service = new LocalOrchestrationService();
await service.CreateIfNotExistsAsync();
await service.StartAsync();

var worker = new TaskHubWorker(service);
worker.AddTaskOrchestrations(typeof(UpperCaseOrchestrator));
await worker.StartAsync();

var client = new TaskHubClient(service);
var instance = await client.CreateOrchestrationInstanceAsync(typeof(UpperCaseOrchestrator), "hello world");
    
var state = await client.WaitForOrchestrationAsync(instance, TimeSpan.FromMilliseconds(100000));
Console.WriteLine($"Output: {state.Output}");

await worker.StopAsync(true);

public class UpperCaseOrchestrator : TaskOrchestration<string, string>
{
    public override async Task<string> RunTask(OrchestrationContext context, string input)
    {
        Console.WriteLine($"Input: {input}");
        await Task.Delay(100).ConfigureAwait(false);
        Console.WriteLine($"Done waiting");

        return input.ToUpperInvariant();
    }
}

My csproj file:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="Microsoft.Azure.DurableTask.Emulator" Version="2.5.4" />
      <PackageReference Include="Microsoft.Azure.DurableTask.Core" Version="2.5.6" />
    </ItemGroup>

</Project>

(I am using .net 6.0 rc1 here, but in the bigger project I am using netcoreapp3.1)

Hope something can point me in the right direction 😃

EDIT: Whether ConfigureAwait is used in the orchestration does not make any difference.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
petertiedemanncommented, Oct 5, 2021

Thanks. I am just so used to writing ConfigureAwait(false) that i don’t even think about it 😃

Looking forward to continuing trying this out, the ability to work with remote long running tasks using async await is really nice.

1reaction
cgillumcommented, Oct 5, 2021

Yes, ConfigureAwait(false) creates the exact same problem as Task.Delay. The orchestration scheduler gets confused if a task continuation is scheduled on any thread but the main execution thread, resulting in problems like this. We are able to detect it if you make calls to other context operations after awaiting, but it looks like you didn’t make any calls after this, thus it went undetected by our runtime checks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Orchestrator stuck waiting for activity task completion #555
Based on my investigation it looks like it is awaiting for an activity to complete that was started. While trying to debug it...
Read more >
Waiting for an azure function durable orchestration to ...
which basically picks up the message, starts the orchestration and then in a do/while loop waits while the staus is Pending or Running....
Read more >
Manage instances in Durable Functions - Azure
Orchestrations in Durable Functions are long-running stateful functions that can be started, queried, suspended, resumed, and terminated using ...
Read more >
Testing-library: avoid these mistakes in async tests
As waitFor is non-deterministic and you cannot say for sure how many times it will be called, you should never run side-effects inside...
Read more >
Handling external events in Durable Functions - Azure
The "wait-for-external-event" API waits indefinitely for some input. The function app can be safely unloaded while waiting. If and when an event ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found