Skip to content

[release/3.1] Use scoped query logger from QueryContext#21025

Merged
smitpatel merged 1 commit intorelease/3.1from
smit/patch
Jun 10, 2020
Merged

[release/3.1] Use scoped query logger from QueryContext#21025
smitpatel merged 1 commit intorelease/3.1from
smit/patch

Conversation

@smitpatel
Copy link
Contributor

@smitpatel smitpatel commented May 22, 2020

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 smitpatel changed the title Use scoped query logger from QueryContext (#21024) [release/3.1] Use scoped query logger from QueryContext (#21024) May 22, 2020
@smitpatel smitpatel changed the title [release/3.1] Use scoped query logger from QueryContext (#21024) [release/3.1] Use scoped query logger from QueryContext May 22, 2020
@smitpatel
Copy link
Contributor Author

smitpatel commented May 22, 2020

Description

EF 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 Impact

This 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 found

Reported by customer in #21016. We think many other customers may be hitting this without realizing that significant extra memory is being used.

Test coverage

Automated 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.

Risk

Low. Also quirked.

@ajcvickers ajcvickers added this to the 3.1.x milestone Jun 6, 2020
@leecow leecow modified the milestones: 3.1.x, 3.1.6 Jun 9, 2020
@ajcvickers
Copy link
Contributor

@smitpatel Approved by Tactics; please wait for 3.1.6 branding before merging.

@smitpatel smitpatel added blocked and removed blocked labels Jun 9, 2020
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
@wtgodbe
Copy link
Member

wtgodbe commented Jun 10, 2020

@smitpatel branches are open for 3.1.6, want me to merge this?

@smitpatel
Copy link
Contributor Author

Already working on it. 😄

@smitpatel smitpatel merged commit 7b8f6fe into release/3.1 Jun 10, 2020
@smitpatel smitpatel deleted the smit/patch branch June 10, 2020 17:27
@ajcvickers ajcvickers removed this from the 3.1.6 milestone Jul 14, 2020
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