Azure / Azure/azure-functions-dotnet-worker

AspNetCore worker extension throwing task already completed exception

Open
#3,024 1 comment 0 reactions 0 assignees View on GitHub
enhancement Needs: Triage (Functions)
Dominant language
C#
Stars
466
Forks
215
Avg merge
3d 10h
Merged PRs (30d)
7

Description

### Description

This came out of 4.1038 release validation that some of the apps were throwing following exception -

```csharp
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.UserTournamentChallengeAsync ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: Failure
Exception: An attempt was made to transition a task to a final state when it had already completed.
Stack:
at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.DefaultHttpCoordinator.SetFunctionContextAsync(String invocationId, FunctionContext context) in /mnt/vss/_work/1/s/extensions/Worker.Extensions.Http.AspNetCore/src/Coordinator/DefaultHttpCoordinator.cs:line 48
```

The function apps were not down and triggers were executing successfully. This error was noticed intermittently followed by below Host logs. Looks like a race condition.

```
The function invocation failed to proxy the request with ForwarderError: RequestCanceled
The client disconnected while the function was processing the request.
```

Teams thread for reference - [Link](https://teams.microsoft.com/l/message/19:e44959e7f62849c4a45e1cd43d607448@thread.tacv2/1744063499538?tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47&groupId=201c2bb2-812d-4986-ac92-9bfad0d6cc59&parentMessageId=1744063499538&teamName=Azure%20Functions%20Team&channelName=Release%20-%20Announcements%20and%20Process&createdTime=1744063499538)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in extensions/Worker.Extensions.Http.AspNetCore/src/Coordinator/DefaultHttpCoordinator.cs at SetFunctionContextAsync, line 48, and review the related invocation and request-cancellation flow. Use the reported task-already-completed exception and Host ForwarderError: RequestCanceled logs as the failure case; done means the intermittent race no longer produces that exception during client disconnects.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.