Azure / azure-cosmos-dotnet-v3

.NET SDK for Azure Cosmos DB for the core SQL API
MIT License
736 stars 492 forks source link

UpsertItemAsync with ItemOptions.IfMatchEtag not work sometimes #4449

Closed htzhang2 closed 4 months ago

htzhang2 commented 5 months ago

We are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.

Describe the bug UpsertItemAsync with same IfMatchEtag value both return success

To Reproduce

  1. Retrieve etag value from existing item with ReadItemAsync
  2. Call to UpsertItemAsync with IfMatchEtag value from step 1.
  3. Another call to UpsertItemAsync with IfMatchEtag value.

Expected behavior

  1. One call succeed
  2. Another call fail with CosmosException.PreConditionFailed

Actual behavior Both calls succeed sometimes

Environment summary SDK Version: 3.38.1 OS Version (e.g. Windows, Linux, MacOSX): Windows

Additional context CosmosDb is strong consistency

bartelink commented 5 months ago

Both calls succeed sometimes

So you're saying you have a repro where two different writes succeed based off the same etag, i.e. the written data from one of the cases is lost? That's declaring SELECT broken, and is highly unlikely to be the case - you'll need to rig a real test case harness for this rather than just loosely alleging 'sometimes'; strong allegations require strong evidence. If this is not what you mean, I'd suggest to modify the expecation

ealsur commented 5 months ago

If this is really happening you will probably need to file a Support Request. What you are describing would be a failure on the Service behavior enforcing ETag matching.

Can you share a repro? Are you certain you are using the same ETag?

From the SDK perspective, the SDK just sends the headers, it does not perform any validation, so there is really nothing that we can do if this ends up being true.

microsoft-github-policy-service[bot] commented 4 months ago

@htzhang2 this issue requires more information for the team to be able to help. In case this information is available, please add it and re-open the Issue.