Open starteleport opened 3 years ago
@starteleport Sorry for being so late, but I just saw this. Wouldn't you need the lock and ConcurrentDictionary though? For the sake of scoping, you cannot ever allow more than one resolver to be built.
We're encountering this same issue when accessing the service provider within our health checks. And yes the lock and ConcurrentDictionary
should be used to ensure only one instance is ever resolved.
@jeremydmiller ~Will you accept a PR for this for the 4.x version of Lamar
? We're not in a position to switch to net5 yet for the project's we're encountering this problem in.~
For some reason I missed that the 5.0 version is multi-targeting netstandard2.0
. I'm putting together a PR for this now.
I've encountered the following error with built-in ASPNET Core (netcoreapp3.1) healthchecks engine.
I've got several MongoDB healthchecks that are registered as Scoped. DefaultHealthCheckService starts all the healthchecks in parallel like this:
The problem seems to be that lambda returned from GeneratedInstance.BuildFuncResolver is not thread-safe. The problem reproduces when:
s.Services.Add
method (here), and then initializes_buckets
array and yet to initialize_entries
array in Dictionary.Inititalizes.Services.TryGetValue
method outside the lock and gets NullReferenceException hereI get rather stable reproduce on NDA'd code base and so far have not succeeded in creating stand-alone repro.
I've got two questions:
GeneratedInstance
switched toConcurrentDictionary
and report whether the problem goes away. Do I need to put effort in reproducing the problem in stand-alone app, or this description is clear enough?Thanks.