[SERVER-21280] document was updated by two processes simultaneously Created: 04/Nov/15  Updated: 31/May/17  Resolved: 21/Mar/17

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.6.9
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Christian Amor Kvalheim Assignee: Mark Agarunov
Resolution: Incomplete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to NODE-574 Concurrency issues with findOneAndUpdate Closed
Operating System: ALL
Participants:

 Description   

User is performing findAndModify operations against sharded system and seeing. All logs and information in linked ticket.

Document with '_id' field of
'545153955055485549534855535651505510110055575410053534899489756519852549573773'
was updated by two processes simultaneously at 2015-11-03 12:30:51.866 and
2015-11-03 12:30:51.952
Thanks



 Comments   
Comment by Mark Agarunov [ 06/Mar/17 ]

Hello annaguri,

We haven't heard back from you in a while regarding the issue you had reported in NODE-574. Are you still experiencing this behavior? If so, what are the steps to take to reproduce the issue?

Thanks,
Mark

Comment by Christian Amor Kvalheim [ 04/Nov/15 ]

according to the information she provided no.

Our Node.js application uses findOneAndUpdate API in order to update a document.
Per MongoDB documentation findOneAndModify is atomic API and "update document if current" approach should avoid data inconsistency or conflicts.
http://docs.mongodb.org/manual/tutorial/update-if-current/
I've noticed that findOneAndUpdate not always behaves as an atomic API.
The scenario is as follows:
The application retrieves a document from MongoDB using the following query:
Collection.find({"Posted" :

{ $exists: false}

}, queryOptions)
Thereafter, it calls the findOneAndUpdate API to set the 'Posted' field.

Collection.findOneAndUpdate(
   {"SId" : eventDoc.SId, "SequenceNumber": eventDoc.SequenceNumber, "Posted" : { $exists: false}},
   {$set : {"Posted" : "processing"},
   {returnOriginal: false},
   function(updtErr, updtEventDoc) {
     if (updtErr) {
       // handle error
     }
     else if (updtEventDoc.value == null) {
      // document was updated by another process
     }
     else {
       // document has been modified successfully 
     }
  }
);

I expect the update to modify the document only if the 'Posted' field was not set by another process since the find query.
However, sometimes the same document is updated successfully by multiple processes - findOneAndUpdate returns the modified document with the 'Posted' field set to 'processing' (I expect only one process to get the updated document while others get 'null').
Another issue I see with the API is that the callback function is never called (although, the document is updated in DB).
The issue is intermittent.
Is that a known issue?
MongoDB version is 2.6.9

Comment by Christian Amor Kvalheim [ 04/Nov/15 ]

All logs and information is in this ticket.

Generated at Thu Feb 08 03:56:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.