[SERVER-8496] _id values generated by mongod are not thread safe across databases, may cause mongod to generate duplicate ids for a single collection (resulting in insert failure) Created: 10/Feb/13 Updated: 11/Jul/16 Resolved: 13/Feb/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Concurrency, Storage |
| Affects Version/s: | 2.2.3, 2.3.2 |
| Fix Version/s: | 2.4.0-rc1 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Aaron Staple | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Participants: |
| Description |
|
DataFileMgr::insert is typically called with a database level write lock, for example when an insert operation request is received on the wire receivedInsert() will acquire such a lock and call checkAndInsert() which calls DataFileMgr::insertWithObjMod() which calls DataFileMgr::insert(). The implementation of DataFileMgr::insert() checks for an existing id in the document to be inserted. If no _id is found, a new ObjectId is generated and added. The implementation for adding an ObjectId uses the static global variables idToInsert and idToInsert. First the OID member of idToInsert_ is initialized with its init() method. Then the idToInsert object is byte copied into the on disk representation of the document to be inserted. If two threads are concurrently inserting into two separate databases, possible race conditions include:
Test
Run two instances of the test concurrently (on different databases using the first command line arg). It can take several minutes to observe the first dup key error. This bug will only manifest when clients do not insert _id fields and mongod generates _ids itself. |
| Comments |
| Comment by auto [ 13/Feb/13 ] |
|
Author: {u'date': u'2013-02-13T04:59:06Z', u'name': u'Eliot Horowitz', u'email': u'eliot@10gen.com'}Message: |
| Comment by Aaron Staple [ 10/Feb/13 ] |
|
Putting in 2.4.0-rc1 for triage. This issue is in 2.2 as well as 2.3. |