You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There appears to be a bug in Extensions.Http.AspNetCore during function completion. When a Http invocation gets cancelled, an InvalidOperationException is thrown instead of expected TaskCanceledException.
This occurs because during cancellation we cancel the CancellationTokenSource in the invocation handler:
Description
There appears to be a bug in
Extensions.Http.AspNetCore
during function completion. When a Http invocation gets cancelled, anInvalidOperationException
is thrown instead of expectedTaskCanceledException
.This occurs because during cancellation we cancel the CancellationTokenSource in the invocation handler:
azure-functions-dotnet-worker/src/DotNetWorker.Grpc/Handlers/InvocationHandler.cs
Line 147 in ca7afd2
This completes the
_functionCompletionTask
:azure-functions-dotnet-worker/extensions/Worker.Extensions.Http.AspNetCore/src/Coordinator/ContextReference.cs
Lines 35 to 45 in ca7afd2
When
CompleteFunction
is called the_functionCompletionTask
task is already complete, but we try to set the result here anyway:azure-functions-dotnet-worker/extensions/Worker.Extensions.Http.AspNetCore/src/Coordinator/ContextReference.cs
Lines 53 to 60 in ca7afd2
Which leads to the
InvalidOperationException
exception.Exception: System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
Repro
Repro can be found in this GH issue:
Fix
First we can implement a check at the start of
CompleteFunction
to see if the task is complete before trying to set a result i.e.This still leads to a different exception
FunctionInvocationException
with aTaskCanceledException
inner exception.If there are other enhancements to make here, they should be considered.
The text was updated successfully, but these errors were encountered: