[release/3.1] Use scoped query logger from QueryContext#21025
[release/3.1] Use scoped query logger from QueryContext#21025smitpatel merged 1 commit intorelease/3.1from
Conversation
DescriptionEF uses logger for when executing the query which is scoped service. Any scoped service instances are not supposed to be in compiled query delegate which gets stored in memory cache. Currently it incorrectly used the logger which was available during compilation phase, which makes the cached delegate hold onto a scoped service causing memory leak. Customer ImpactThis can easily cause a significant memory leak where a DbContext instance and all its tracked entities remain in-memory potentially for the life of the application because they are referenced from the query cache. How foundReported by customer in #21016. We think many other customers may be hitting this without realizing that significant extra memory is being used. Test coverageAutomated testing is hard for this because we have to prove that there isn't a memory leak from the internal cache. We have done manual testing at this time and are thinking about how we can better test things like this going forward. Regression?Yes, from 2.x. RiskLow. Also quirked. |
|
@smitpatel Approved by Tactics; please wait for 3.1.6 branding before merging. |
Resolves #21016 All scoped services used while executing the query comes from QueryContext. All scoped services on QueryCompilationContext should only be used while compiling the query and should not be made part of QueryExecutorLambda. Singleton services comes from QueryCompilationContext and added to the QueryExecutorLambda directly during compilation. Cherry-pick of #21024 on release/3.1
|
@smitpatel branches are open for 3.1.6, want me to merge this? |
|
Already working on it. 😄 |
Resolves #21016
Cherry-pick of #21024 on release/3.1