odata.net icon indicating copy to clipboard operation
odata.net copied to clipboard

OData .NET Lib 5.x - Version 5.8.5 broken thread safety

Open uffelauesen opened this issue 3 years ago • 0 comments

The changes introduced in the V3 library 5.8.5 breaks thread safety.

Assemblies affected

OData .Net lib 5.8.5

Reproduce steps

Execute 2 or more queries on the same resource set in parallel with navigation, like...

        var query = from h in ctx.Something
                    where h.ID == "1"
                    select h.Related;

Often this will lead to an NotSupportedException from ResourceBinder.cs ValidationRules.RequireCanNavigate as the EdmEntityType creation has gone wrong due to not being thread safe anymore. It can lead to an issue situation where ID is not detected as being the Key property of the Something entity type. Full message and stacktrace thrown...

Message: Test method Scanjour.Services.OData.Test.Integration.GenericQueryTests.Select_NonExistingReference threw exception: System.NotSupportedException: Can only specify query options (orderby, where, take, skip) after last navigation.

Stack Trace: ValidationRules.RequireCanNavigate(Expression e) line 2446 ResourceBinder.IsValidNavigationSource(Expression input, ResourceExpression& sourceExpression) line 605 ResourceBinder.AnalyzeNavigation(MethodCallExpression mce, DataServiceContext context) line 591 ResourceBinder.VisitMethodCall(MethodCallExpression mce) line 1406 ALinqExpressionVisitor.Visit(Expression exp) line 191 DataServiceALinqExpressionVisitor.Visit(Expression exp) line 58 ResourceBinder.Bind(Expression e, DataServiceContext context) line 88 DataServiceQueryProvider.Translate(Expression e) line 160 DataServiceQuery1.Translate() line 317 DataServiceQuery1.Execute() line 161 DataServiceCollection1.InternalLoadCollection(IEnumerable1 items) line 802 DataServiceCollection1.StartTracking(DataServiceContext context, IEnumerable1 items, String entitySet, Func2 entityChanged, Func2 collectionChanged) line 910 DataServiceCollection1.ctor(DataServiceContext context, IEnumerable1 items, TrackingMode trackingMode, String entitySetName, Func2 entityChangedCallback, Func2 collectionChangedCallback) line 233 DataServiceCollectionExtensions.ToDataServiceCollection[T](IEnumerable`1 items) line 21 GenericQueryTests.Select_NonExistingReference() line 1705

Expected result

No exceptions and it should work when running multithreaded.

Actual result

NotSupportedException might be thrown due to 5.8.5 has removed thread safety on EdmEntity type runtime creation.

Additional detail

5.8.4 behaves fine. It was a bit difficult to figure out what changes were made in 5.8.5 that broke the thread safety as the changes have not been merged to the GitHub repo, but the breaking changes are documented here https://github.com/MicrosoftDocs/OData-docs/blob/main/Odata-docs/changelog/odatalib-5x.md

uffelauesen avatar Jul 05 '22 13:07 uffelauesen