Skip to content

Conversation

roji
Copy link
Member

@roji roji commented Aug 2, 2025

Port of #36484 for EF 9.0.x.
Fixes #34280

Description
When a user executes a LINQ query that has a final GroupBy() (GroupBy as the very last operator), and executes as a split query, EF does not properly dispose the database reader(s) it uses to read back the results (these are IDisposable).

Customer impact
Depending on the provider, when executing a LINQ query that uses a final GroupBy() and is configured for split querying, the database connection may get leaked and never returned to the connection pool. This later leads to an exhausted connection pool and to an application failure in a way that's hard to track down and connect to the actual problematic EF LINQ query.

How found
Two users reported.

Regression
No - this bug was present when the final GroupBy feature was first introduced in EF 7.0 (in #19929)

Testing
Adding test coverage here is quite difficult/impractical - the bug is that a certain internal resource (DbDataReader) doesn't get disposed, which isn't something visible we can check.

Risk
Extremely low. The fix is very targeted and simply does the as for very similar other code (e.g. non-GroupBy SplitQueryingEnumerable).

@SamMonoRT SamMonoRT requested a review from AndriySvyryd August 3, 2025 19:47
@SamMonoRT
Copy link
Member

cc @artl93

@roji
Copy link
Member Author

roji commented Aug 4, 2025

Approved via email.

@roji roji merged commit b460f82 into dotnet:release/9.0-staging Aug 4, 2025
7 checks passed
@roji roji deleted the release/9.0-staging branch August 4, 2025 22:24
This was referenced Sep 9, 2025
This was referenced Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants