DataServiceContext.ApplyingChanges stuck to True in multithread scenario
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 732
- Forks
- 356
- Avg merge
- 22h 57m
- Merged PRs (30d)
- 16
Description
Hi,
I'm having an issue in my production application (VB.NET) that does not occurs in my proof of concept application (C#).
I tried updating all nuget to latest version and i'm using VB.NET 4.6.1,
also removed old OData nuget in case there could be in conflict. NOT RELEATED
I will try in a VB.NET proof of concept application just to be sure it is not language specific. CONFIRMED
Does it ring a bell for someone? Any pointer would be very appreciated...
Assemblies affected
Microsoft.OData.Client, Version=7.5.0.20627
Microsoft.OData.Client.DataServiceCollection(Of T)
Reproduce steps
Adding an object in the DataServiceCollection object, properly instanciated with the context and everything simply doesn't work.
I'm able to read object, so there is no issue with the authentication or generated code.
When I call the DataServiceContext.SaveChanges method, nothing happens...
Investigating further shows me that the DataServiceContext.Entities collection is empty after adding the object in the DataServiceCollection.
I can confirm the object is the right type and is added to the DataServiceCollection, only the 'tracking link' with the DataServiceContext is missing...
Expected result
Object being tracked
Actual result
Object not tracked
*********************** UPDATE *****************************
Here's an update!
The issue occurs because the DataServiceContext.ApplyingChanges is stuck to True, preventing addition to the tracked entities...
Additional info
It seems the MaterializeFromAtom.MoveNext() method cause issue in mutithreading, as the local 'applying' variable takes the value before and set it back after.
In my case two query are sent, the first take applying value when false and set it to true, the second take it when true and also set it to true.
When the first query returns, it reset the applying variable to false and when the second query returns it reset the variable to what it was before, so it reset it to true.
This is why the DataServiceContext.ApplyingChanges is stuck to true forever.
Should I wait and send only one query at a time, multithread querying was to get better performance...
Thanks a lot!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at MaterializeFromAtom.MoveNext() and reproduce the issue with two concurrent queries against DataServiceContext. Check the ApplyingChanges state transitions while objects are added to DataServiceCollection, then verify that concurrent query completion leaves entities tracked and allows SaveChanges to act.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100