2
Vote

Microsoft.OData.Edm and thread safety

description

When multiple threads try to call DataServiceQueryProvider.Execute using different DataServiceContext instances, an exception is thrown internally when they access the shared EDM model.

Please consider using thread-safe dictionaries to allow using multiple DataServiceContext concurrently.
An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsNavigationSource.FindNavigationTarget(IEdmNavigationProperty property)
   at Microsoft.OData.Core.JsonLight.ODataJsonLightReader.StartNavigationLink(ODataJsonLightReaderNavigationLinkInfo navigationLinkInfo)
   at Microsoft.OData.Core.JsonLight.ODataJsonLightReader.ReadAtNavigationLinkEndImplementationSynchronously()
   at Microsoft.OData.Core.JsonLight.ODataJsonLightReader.ReadAtNavigationLinkEndImplementation()
   at Microsoft.OData.Core.ODataReaderCore.ReadImplementation()
   at Microsoft.OData.Core.ODataReaderCore.ReadSynchronously()
   at Microsoft.OData.Core.ODataReaderCore.InterceptException[T](Func`1 action)
   at Microsoft.OData.Core.ODataReaderCore.Read()
   at Microsoft.OData.Client.Materialization.ODataReaderWrapper.Read()
   at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.TryRead()
   at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.AssertRead()
   at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.ReadEntryCore()
   at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.TryReadFeedOrEntry(Boolean lazy, ODataFeed& feed, MaterializerEntry& entry)
   at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.Read()
   at Microsoft.OData.Client.Materialization.ODataReaderEntityMaterializer.ReadNextFeedOrEntry()
   at Microsoft.OData.Client.Materialization.ODataEntityMaterializer.ReadImplementation()
   at Microsoft.OData.Client.Materialization.ODataMaterializer.Read()
   at Microsoft.OData.Client.MaterializeAtom.MoveNextInternal()
   at Microsoft.OData.Client.MaterializeAtom.MoveNext()
   at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Microsoft.OData.Client.DataServiceQueryProvider.ReturnSingleton[TElement](Expression expression)
   at Microsoft.OData.Client.DataServiceQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source)

comments

PinpointTownes wrote Aug 8, 2014 at 6:26 PM

Web API is similarly impacted when it tries to call Microsoft.OData.Edm.Library.EdmNavigationSource.FindNavigationTarget concurrently.

ccbeloy wrote Feb 27, 2015 at 1:30 PM

The latest release "Microsoft ASP.NET Web API 2.2 for OData v4.0 5.4.0" seems to fixed this issue, I can't reproduce it anymore. Can someone confirm and verify this and flip the Status accordingly?