Skip to content

Conversation

pakrym
Copy link

@pakrym pakrym commented Feb 1, 2019

The race that was happening is the following:

  1. IL compilation is kicked off for the service on the background thread
  2. The container is disposed clearing singleton cache
  3. As optimization IL compilation tries to resolve direct reference to a singleton service that it knows should already be resolved and cached
  4. Because the cache is cleared new object is created triggering the Assert.

The solution is to keep service cache around and let GC clean it.

Fixes: #1043

@pakrym pakrym requested review from Tratcher and halter73 February 1, 2019 20:35
// Not clearing ResolvedServices here because there might be a compilation running in background
// trying to get a cached singleton service instance and if it won't find
// it it will try to create a new one tripping the Debug.Assert in CaptureDisposable
// and leaking a Disposable object in Release mode
Copy link
Member

Choose a reason for hiding this comment

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

What should happen in CaptureDisposable if the container is already disposed? Shouldn't we throw an ODE that can be observed by the top-level GetService() call?

Copy link
Author

Choose a reason for hiding this comment

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

It shouldn't get called after dispose. We have ODE checks on all customer accessed entry points. This one is internal that that's why it was able to slip past those checks.

@pakrym pakrym merged commit 0947a8d into master Feb 1, 2019
@JunTaoLuo JunTaoLuo deleted the pakrym/dont-clear-services branch February 2, 2019 02:36
maryamariyan pushed a commit to maryamariyan/runtime that referenced this pull request Feb 28, 2020
maryamariyan pushed a commit to maryamariyan/runtime that referenced this pull request Mar 2, 2020
maryamariyan pushed a commit to maryamariyan/runtime that referenced this pull request Mar 11, 2020
maryamariyan pushed a commit to maryamariyan/runtime that referenced this pull request Mar 27, 2020
@ghost ghost locked as resolved and limited conversation to collaborators May 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failure : Hosting tests fail on Windows in Debug mode

3 participants