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

[release/8.0] Keep parameter values out IMemoryCache in RelationalCommandCache #34908

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

roji
Copy link
Member

@roji roji commented Oct 14, 2024

Store only nullness and array lengths in struct form to prevent parameters memory leaks

Fixes #34028
Backports #34028

Description
EF's query pipeline contains a SQL cache, whose key contains the nullness of parameters; this is needed since different nullness requires different SQL (e.g. WHERE b.Name = @p (where p is non-null), vs. WHERE b.Name IS NULL (where p is null)). The cache key implementation currently references the parameter value, rather than just recording whether it was null or not. This causes user data to be referenced from internal caching, keeping potentially large amounts of data referenced and preventing the GC from reclaiming them.

Customer impact
In some cases, large amounts of user data will be kept in memory and will never get garbage-collected.

How found
Customer reported on 8.0

Regression
No

Testing
Testing that a reference is kept to an object isn't feasible in a reliable way.

Risk
Low.

Store only nullness and array lengths in struct form to prevent parameters memory leaks

Fixes dotnet#34028

Co-authored-by: Shay Rojansky <[email protected]>

(cherry picked from commit af420cd)
@roji roji requested a review from a team October 14, 2024 20:54
@AndriySvyryd
Copy link
Member

Consider adding a quirk mode

@roji
Copy link
Member Author

roji commented Oct 14, 2024

Consider adding a quirk mode

Done, PTAL. Should we include the quirk in 9.0 as well, given that GA is right around the corner? Feels like if we want to potentially give people a way out of this change for 8.0, the same should hold for 9.0 at this point.

@AndriySvyryd
Copy link
Member

Should we include the quirk in 9.0 as well, given that GA is right around the corner

9.0 is not LTS, so I think it's just a bit more risk-tolerant.

@roji roji enabled auto-merge (squash) October 14, 2024 22:57
@roji roji merged commit 38f72ca into dotnet:release/8.0 Oct 14, 2024
7 checks passed
@roji roji deleted the release/8.0 branch October 14, 2024 23:47
private readonly Dictionary<string, ParameterInfo> _parameterInfos;

// Quirk only
private readonly IReadOnlyDictionary<string, object?>? _parameterValues;

public CommandCacheKey(Expression queryExpression, IReadOnlyDictionary<string, object?> parameterValues)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, still getting this leak. Primary constructor still holding it probably

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bleapleaper can you please open a new issue with a minimal, runnable repro that shows this still happening after the fix?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unable to repro with the repro in the issue, but in another project i still see the leak. Investigating further. Too trigger happy on the comments sorry

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.

4 participants