durabletask-dotnet: DurableTaskClient.PurgeAllInstancesAsync: NotSupportedException and RpcException for .net 8 isolated

I am periodically purging instances and old history of my durable function runs. We noticed that this logic stopped working some time ago.

Runtime: .net 8 isolated azure function

Dependencies:

<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.2" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />

My TimerTrigger Azure Function which is implemented next to my durable function looks likes this:

    [Function(nameof(OrchestrationCleanupFunction))]
    public async Task Run(
        [TimerTrigger("0 */1 * * * *")] TimerInfo myTimer,
        [DurableClient] DurableTaskClient orchestrationClient)
    {
        var createdTimeFrom = DateTime.UtcNow.Subtract(TimeSpan.FromDays(365 * 5));
        var createdTimeTo = DateTime.UtcNow.Subtract(TimeSpan.FromDays(5));

        var runtimeStatus = new List<OrchestrationRuntimeStatus>
        {
            OrchestrationRuntimeStatus.Completed
        };

        await orchestrationClient.PurgeAllInstancesAsync(new PurgeInstancesFilter(createdTimeFrom, createdTimeTo, runtimeStatus));
    }

This code worked at some point and was initially developed as .Net 7 isolated function.

Now i am getting a System.NotSupportedException: Microsoft.Azure.Functions.Worker.FunctionsDurableTaskClient does not support purging of orchestration instances.

The implementation of DurableTaskClient.PurgeAllInstancesAsync is very confusing.

  • DurableTaskClient is abstract and has multiple virtual overloads of PurgeAllInstancesAsync with a default implementation that throws a System.NotSupportedException.
  • Each derived type does not override all “virtual” variations of PurgeAllInstancesAsync. (GrpcDurableTaskClient & FunctionsDurableTaskClient)

Example: FunctionsDurableTaskClient implements: Task<PurgeResult> PurgeAllInstancesAsync(PurgeInstancesFilter filter, CancellationToken cancellation) but not public virtual Task<PurgeResult> PurgeAllInstancesAsync( PurgeInstancesFilter filter, PurgeInstanceOptions? options = null, CancellationToken cancellation = default)

So calling: client.PurgeAllInstancesAsync(new PurgeInstancesFilter(...), CancellationToken.None); and client.PurgeAllInstancesAsync(new PurgeInstancesFilter(...)); makes an unexpected difference.

On top, i am getting a RpcException with {“Status(StatusCode="Unknown", Detail="Exception was thrown by handler.")”} locally and on Azure.

I would greatly appreciate some help getting this purge implementation up and running.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 5
  • Comments: 20 (6 by maintainers)

Most upvoted comments

I’ve encountered this issue as well. Rolling back Microsoft.Azure.Functions.Worker.Extensions.DurableTask to 1.1.0 fixes the issue, it appears to be a regression in v1.1.2 of that package.

Thanks all, sorry we did not catch this. I’ll see if we can fix this in our upcoming releae.

Thanks for letting us know. @andystaples - please make sure this is tracked, thanks 😃

cc @cgillum, @jviau - in case this is still an issue ^.

@Mivaweb - are you saying that if you perform PurgeAllInstancesAsync without first performing a ‘GET’ to an instance, you get an exception? Any chance you could describe a minimal repro? Thanks!

@davidmrdavid yes correct.

Here is my code sample:

[Function(CleanupStarterName)]
public async Task Start(
    [TimerTrigger("%CleanupStarterSchedule%")] TimerInfo timerInfo,
    [DurableClient] DurableTaskClient starter)
{
    var createdTimeTo = DateTime.UtcNow.Subtract(TimeSpan.FromDays(_esbConfig.InstanceHistoryCleanupInDays));
    var runtimeStatus = new List<OrchestrationRuntimeStatus>
    {
        OrchestrationRuntimeStatus.Completed,
        OrchestrationRuntimeStatus.Failed,
        OrchestrationRuntimeStatus.Terminated
    };

    try
    {
        //var instances = starter.GetAllInstancesAsync(new OrchestrationQuery(null, createdTimeTo, runtimeStatus));
        //var pendingDeleteTasks = (await instances.AsPages().ToListAsync())
        //    .SelectMany(i => i.Values)
        //    .Select(i => i.InstanceId)
        //    .Select(i => starter.PurgeInstanceAsync(i))
        //    .ToList();

        //_logger.Info<CleanupStarterFunction>("Deleting '{Count}' instances.", parameters: [pendingDeleteTasks.Count]);

        //await Task.WhenAll(pendingDeleteTasks);

        var result = await starter.PurgeAllInstancesAsync(new PurgeInstancesFilter(
            null,
            createdTimeTo,
            runtimeStatus));
    }
    catch(Exception ex)
    {
        _logger.Error<CleanupStarterFunction>(ex, "Failed to cleanup instances.");
    }
}

Which results in:

Grpc.Core.RpcException
  HResult=0x80131500
  Message=Status(StatusCode="Unknown", Detail="Exception was thrown by handler.")
  Source=Microsoft.DurableTask.Client.Grpc
  StackTrace:
   at Microsoft.DurableTask.Client.Grpc.GrpcDurableTaskClient.<PurgeInstancesCoreAsync>d__25.MoveNext()
   at ESB.Durable.SDK.Starters.CleanupStarterFunction.<Start>d__3.MoveNext() in ...\CleanupStarterFunction.cs:line 49

  This exception was originally thrown at this call stack:
    [External Code]
    ....CleanupStarterFunction.Start(Microsoft.Azure.Functions.Worker.TimerInfo, Microsoft.DurableTask.Client.DurableTaskClient) in CleanupStarterFunction.cs

@andystaples let’s take a closer look at the issues mentioned here as part of the e2e testing work that you’re doing.

Still getting the error in Net 8 (Isolated):

Result: Failure Exception: Grpc.Core.RpcException: Status(StatusCode=“Unknown”, Detail=“Exception was thrown by handler.”) at Microsoft.DurableTask.Client.Grpc.GrpcDurableTaskClient.PurgeInstancesCoreAsync(PurgeInstancesRequest request, CancellationToken cancellation) at …

Dependencies

<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.22.0" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" /> <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.4" />

we are getting this issue when executing:

` var filter = new PurgeInstancesFilter( DateTime.MinValue, createdToTimeResult, new List<OrchestrationRuntimeStatus> { OrchestrationRuntimeStatus.Completed, OrchestrationRuntimeStatus.Failed, OrchestrationRuntimeStatus.Terminated });

await durableTaskClient.PurgeAllInstancesAsync(filter);

`

is there a fix for this?, thanks in advance

@gfgw I’m currently using TerminateInstanceAsync(string instanceId, object? output, CancellationToken cancellation = default(CancellationToken)) as a temporary fix, it is only Task TerminateInstanceAsync(string instanceId, TerminateInstanceOptions? options = null, CancellationToken cancellation = default(CancellationToken)) that is throwing the unintended exception in the latest version

This fix doesn’t appear to have made it into 1.1.3, any idea when we’ll get it? (unless Microsoft.Azure.Functions.Worker.FunctionsDurableTaskClient does not support orchestration termination. is strictly speaking a different issue).

Edit: just had a look at the NotSupportedExceptions are still there for Purge too

Edit 2: Just seen 1.2.3 release notes

For me it was enough to downgrade package Microsoft.Azure.Functions.Worker.Extensions.DurableTask from 1.1.2 to 1.1.1.