Retry execution strategy with multiple DbContexts doesn't retry
@AndriySvyryd is already working on this.
Since Dec 2, 2019.
Assessment
This issue has not been assessed yet.
Description
When using execution strategies to retry transient errors we've run into an issue where if one DbContext uses an explicit execution strategy because of a transaction another DbContext won't retry transient errors.
It looks like that's caused by the ExecutionStrategy class using a static AsyncLocal<bool?> to track if it's inside a strategy execution already. Since it's static it's applying to all DbContext rather than just the context the strategy belongs to. That was originally added to fix https://github.com/aspnet/EntityFramework6/issues/16
Steps to reproduce
I tried to simplify what we're actually doing for a small repro in the attached project.
EfConcurrentExecutionStrategy.zip
On startup it runs an execution strategy with a transaction on MainDbContext. While that's running it's using InfrastructureDbContext to write log messages and get the count of log messages. Writing log messages works but reading the log count fails. When the the BackgroundService LoggingWritingService calls LoggingService.WriteLogsAsync the execution strategy's RetriesOnFailure is true but when calling LoggingService.GetLogCountAsync from inside MainDbContext's execution strategy the InfrastructureDbContext's execution strategy's RetriesOnFailure is false.
Further technical details
EF Core version: 3.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET Core 3.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.3.6
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100