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

[6.0] Fix context pooling concurrency issue #26226

Merged
merged 1 commit into from
Oct 4, 2021
Merged

Conversation

roji
Copy link
Member

@roji roji commented Oct 1, 2021

Fixes #26202

Description

When using DbContext pooling, the DbContext disposal logic modifies the state after the context has been returned to the pool, creating a race condition with possible consumers renting the context out of the pool.

Customer impact

When using DbContext pooling, an ObjectDisposedException may occur when using a pooled context. This is the kind of bug that only happens very occasionally but then will cause the application to fail unexpectedly and in a way that is difficult to diagnose. This means lack of customer reports doesn't mean it isn't impacting overall reliability of apps that use EF Core.

How found

Customer reported.

Regression

No; exists in 5.0 also. We intend to backport there. Does not happen on 3.1.

Testing

Test for this scenario added in the PR.

Risk

Low, the fix is quite simple.

We may want to revisit and simplify later, but for now here's a minimal fix.

@roji roji requested a review from ajcvickers October 1, 2021 09:16
@roji roji changed the title Fix context pooling concurrency issue [6.0] Fix context pooling concurrency issue Oct 1, 2021
@roji roji force-pushed the roji/FixContextPooling branch 3 times, most recently from dc78563 to d08f898 Compare October 1, 2021 14:01
@ajcvickers
Copy link
Member

@Pilchie For 6.0. (Also we're going to request backporting to at least 5.0.x, but we'll obviously do that separately.)

@roji
Copy link
Member Author

roji commented Oct 4, 2021

Squashed and rebased on latest release/6.0

@Pilchie
Copy link
Member

Pilchie commented Oct 4, 2021

Approved for EFCore 6.0 GA.

@roji roji merged commit 93ef75f into release/6.0 Oct 4, 2021
@roji roji deleted the roji/FixContextPooling branch October 4, 2021 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ObjectDisposedException on retrieval of a pooled DbContext
4 participants