I’m working on a durable function and would like to be able to cancel the function after a given time. Currently I have setup a timeout on both the start and completion of the instance. The weird thing is that I receive the following exception on the WaitForInstanceCompletionAsync method:
The WaitForInstanceCompletionAsync operation was canceled.
with inner exception:
The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
and source:
Microsoft.DurableTask.Client.Grpc
This while I did set a higher timeout than 100sec.
Here Is the code that triggers the orchestration:
public class Trigger(IMessageMapper<StartOrganizationMessage> mapper)
{
[Function(nameof(Trigger))]
public async Task Run(
[ServiceBusTrigger("pipelinepriorityqueue", Connection = "ServiceBusConnection", IsSessionsEnabled = false)]
ServiceBusReceivedMessage message,
ServiceBusMessageActions messageActions,
[DurableClient] DurableTaskClient taskClient,
FunctionContext context)
{
string? instanceId = null;
try
{
var mappedMessage = mapper.ToApplicationMessage(message);
instanceId = await taskClient.ScheduleNewOrchestrationInstanceAsync($"{nameof(OrganizationOrchestrator)}", Tuple.Create(mappedMessage.OrganizationId, mappedMessage.SecretId, mappedMessage.Farms));
var waitForInstanceStart = new CancellationTokenSource(TimeSpan.FromMinutes(5));
var result = await taskClient.WaitForInstanceStartAsync(instanceId, waitForInstanceStart.Token);
var waitForInstanceCompletion = new CancellationTokenSource(TimeSpan.FromMinutes(10));
result = await taskClient.WaitForInstanceCompletionAsync(instanceId, true, waitForInstanceCompletion.Token);
await messageActions.CompleteMessageAsync(message);
}
catch (Exception ex)
{
await messageActions.DeadLetterMessageAsync(message, deadLetterErrorDescription: ex.Message);
throw;
}
finally
{
await taskClient.PurgeInstanceAsync(instanceId!, new PurgeInstanceOptions { Recursive = true });
}
}
}
I tried setting the functionTimeout in the host.json but that did not seem to do the trick.
I would expect the timeout to occur after the cancelation token. Not after 100sec.
This is happening locally, not yet tried on test but would like to know the reason of this.