Skip to content

Conversation

@ajcvickers
Copy link
Contributor

Fixes #32267
Port of #32345

Description

The problem here is that ILazyLoader is a transient IDisposable service, which means that the service scope will keep track of instances created in the scope. However, when using context pooling, the service scope is not disposed because it is instead re-used. This means that the scope keeps getting more and more instances added, and never clears them out.

The fix is to make the service not IDisposable. Instead, we create instances from our own internal factory where we keep track of the instances created. These can then be disposed and freed when the context is places back in the pool, or when the scope is disposed thus disposing the factory.

This is a breaking change for anyone depending on ILazyLoader being IDisposable.

Customer impact

Memory leak for services using context pooling and lazy loading.

How found

Customer reported on 8.0

Regression

No

Testing

Added.

Risk

Medium; while the chances of anyone relying on ILazyLoader being IDisposable are low, it is nevertheless possible that this change will break someone. It also cannot be quirked.

@ajcvickers ajcvickers changed the base branch from main to release/8.0 November 30, 2023 13:36
@ajcvickers ajcvickers requested a review from a team November 30, 2023 13:36
@ajcvickers ajcvickers added this to the 8.0.x milestone Nov 30, 2023
Fixes #32267

The problem here is that ILazyLoader is a transient IDisposable service, which means that the service scope will keep track of instances created in the scope. However, when using context pooling, the service scope is not disposed because it is instead re-used. This means that the scope keeps getting more and more instances added, and never clears them out.

The fix is to make the service not IDisposable. Instead, we create instances from our own internal factory where we keep track of the instances created. These can then be disposed and freed when the context is places back in the pool, or when the scope is disposed thus disposing the factory.
@AndriySvyryd
Copy link
Member

Note that the branch is currently closed.

@wtgodbe wtgodbe merged commit 01ee6e3 into release/8.0 Jan 3, 2024
@wtgodbe wtgodbe deleted the 231130_BreakDancing branch January 3, 2024 22:36
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.

DB Context pooling with proxies resulting in memory issues in 8.0 RC2

3 participants