This repository was archived by the owner on Nov 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 312
This repository was archived by the owner on Nov 2, 2018. It is now read-only.
Race in ServiceLookup.CallSiteValidator.ValidateCallSite() #467
Copy link
Copy link
Closed
Description
I am getting the following exception when running the EF benchmarks (aspnet/Benchmarks#162):
System.ArgumentException: An item with the same key has already been added. Key: Benchmarks.Data.EfDb
at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(Object key)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.ValidateCallSite(Type serviceType, IServiceCallSite callSite) in C:\Git\DependencyInjection\src\Microsoft.Extensions.DependencyInjection\ServiceLookup\CallSiteValidator.cs:line 19
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType, ServiceProvider serviceProvider) in C:\Git\DependencyInjection\src\Microsoft.Extensions.DependencyInjection\ServiceProvider.cs:line 76
at System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd[TKey,TValue,TArg](ConcurrentDictionary`2 dictionary, TKey key, Func`3 valueFactory, TArg arg) in C:\Git\DependencyInjection\src\Microsoft.Extensions.DependencyInjection\Internal\ConcurrentDictionaryExtensions.cs:line 11
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) in C:\Git\DependencyInjection\src\Microsoft.Extensions.DependencyInjection\ServiceProvider.cs:line 63
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) in C:\Git\DependencyInjection\src\Microsoft.Extensions.DependencyInjection.Abstractions\ServiceProviderServiceExtensions.cs:line 28
at Benchmarks.Middleware.MultipleUpdatesEfMiddleware.<Invoke>d__4.MoveNext() in C:\Git\Benchmarks\src\Benchmarks\Middleware\MultipleUpdatesEfMiddleware.cs:line 0
The issue appears to be a race in ServiceLookup.CallSiteValidator.ValidateCallSite():
public void ValidateCallSite(Type serviceType, IServiceCallSite callSite)
{
var scoped = VisitCallSite(callSite, default(CallSiteValidatorState));
if (scoped != null)
{
_scopedServices.Add(serviceType, scoped);
}
}
pakrym, halter73 and henkmollema