Azure / Azure/azure-functions-host

Scoped registrations resolve same instance between multiple httprequests

Open
#7,605 3 comments 0 reactions 0 assignees View on GitHub
Needs: Attention :wave:
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

We registered our DbContext as scoped, but we noticed, if we start multiple http requests, the context gets shared between the different requests, which leads to threading issues:

{
type: 'NotSupportedException',
message: "A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe."
}

Any feedback on how to fix this would be greatly appreciated.

Our setup:
- We enabled the flag "AzureWebJobsFeatureFlags": "EnableEnhancedScopes",
- Azure functions with HttpTriggers
- added references:
```













```

- project:
```

netcoreapp3.1
v3
<_FunctionsSkipCleanOutput>true

```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing concurrent HTTP-trigger requests with the Azure Functions v3 and EnableEnhancedScopes setup described in the report, then inspect how scoped registrations are created per request. Done means identifying whether the same DbContext instance crosses requests and documenting a verified fix or limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.