Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DbContext: Possible race condition affecting DbContext pooling #7251

Closed
divega opened this issue Dec 15, 2016 · 0 comments
Closed

DbContext: Possible race condition affecting DbContext pooling #7251

divega opened this issue Dec 15, 2016 · 0 comments
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@divega
Copy link
Contributor

divega commented Dec 15, 2016

The original PR to have ASP.NET Core benchmarks use explicitly compiled queries (aspnet/Benchmarks@cd24604) contained a bug in the use of Attach() in LoadMultipleUpdatesRows(): if the random number generator returns duplicate IDs in the same run then Attach() will fail.

@mikeharder pointed out that the expected probability of picking a random number twice or more from a range of 1 to 1001 in 20 attempts should be around 2% but we were seeing around 75% of requests fail.

Switching off DbContext pooling (originally introduced to the benchmarks in aspnet/Benchmarks#154) brings the failure rate to expected values.

The current theory is that somehow the state of DbContext instances is not always correctly reset.

@divega divega added this to the 2.0.0 milestone Dec 22, 2016
anpete added a commit that referenced this issue Jan 24, 2017
- Fixed race condition between pool return and context state reset.
- Added missing dispose checks to DbContext. These are helpful for uncovering pooling issues because pooled instances are treated as disposed when not in use.
@anpete anpete closed this as completed in fd9c545 Jan 25, 2017
@divega divega added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 8, 2017
@ajcvickers ajcvickers changed the title Possible race condition affecting DbContext pooling DbContext: Possible race condition affecting DbContext pooling May 9, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 10, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants