Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[8.0] Resolve query logger from QueryContext in shaper generation (#36758) - #36779

#36779
Merged
roji merged 1 commit into
dotnet:release/8.0-stagingdotnet/efcore:release/8.0-stagingfrom
roji:JsonLeak8roji/efcore:JsonLeak8Copy head branch name to clipboard
Sep 15, 2025
Merged

[8.0] Resolve query logger from QueryContext in shaper generation (#36758)#36779
roji merged 1 commit into
dotnet:release/8.0-stagingdotnet/efcore:release/8.0-stagingfrom
roji:JsonLeak8roji/efcore:JsonLeak8Copy head branch name to clipboard

Conversation

@roji

@roji roji commented Sep 14, 2025

Copy link
Copy Markdown
Member

Instead of closing over the current scoped logger, causing a leak.

Closes #36464, backports #36758 to 8.0

Description
When generating the shaper (code which reads back results from the database), the current logic wrongly captures the current query logger (which is a scoped service); this means that whatever logger is in use when the query is first compiled gets referenced from the shaper, and stored in our singleton query cache potentially forever (or until evicted). The logger has references ultimately leading to the EF change tracker and through it, meaning that these user objects are kept alive forever (a form of leak).

Customer impact
With specific usage, arbitrary large user objects may be kept alive forever, and never garbage-collected. In addition, the wrong query logger instance may get used (the one from when the query was first compiled, instead of the current one for the query being executed), which could lead to incorrect logging.

We have performed patch servicing for this kind of bug before (because of the leak potential).

How found
Customer report

Regression
Yes, from EF 7 to EF 8; introduced in #31100.

Testing
This is unfortunately difficult/possible to test automatically, as it's about an unwanted reference in the shaper keeping objects alive. Tested manually to ensure that the shaper no longer contains the reference.

Risk
Low. The change is simple, and we have ample code coverage for the affected codepaths; quirk added.

…6758)

Instead of closing over the current scoped logger, causing a leak.

Closes dotnet#36464

(cherry picked from commit b7996be)
@roji
roji requested a review from a team September 14, 2025 07:43
@roji
roji merged commit d574040 into dotnet:release/8.0-staging Sep 15, 2025
7 checks passed
@roji
roji deleted the JsonLeak8 branch September 15, 2025 07:06
This was referenced Oct 14, 2025
This was referenced Jul 20, 2026
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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.