Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-7660

findAndModify causes exception when "new" and "upsert" are true and a sort is provided (with auth enabled)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.3, 2.3.1
    • Affects Version/s: 2.2.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      OSX 64bit - 10.8.2 (Mountain Lion)
      CentoOS release 6.3 (Final) - Linux 2.6.32-220.23.1.el6.x86_64 x86_64
    • ALL
    • Hide

      1- Set up (or start) a database server with authentication enabled.
      2- Open the mongodb shell
      3- select database + authenticate
      4- Paste the following in the shell:

      db.testCollection.drop();
      db.testCollection.findAndModify({ 
        query : { foo : 'bar' }, 
        update : { $set : { bob : 'john' } }, 
        sort: { foo : 1}, 
        upsert: true, 
        new : true 
      })
      
      Show
      1- Set up (or start) a database server with authentication enabled . 2- Open the mongodb shell 3- select database + authenticate 4- Paste the following in the shell: db.testCollection.drop(); db.testCollection.findAndModify({ query : { foo : 'bar' }, update : { $set : { bob : 'john' } }, sort: { foo : 1}, upsert: true, new : true })

      findAndModify queries throw an exception if all of the following conditions are met:

      • the query parameter doesn't match an existing object in the collection
      • new is set to true
      • upsert is set to true
      • a sort is provided
      • authentication must be enabled on the server (can't reproduce when auth is disabled)

      Other notes:

      • Indexing has no effect on the ability to reproduce the bug.
      • The sort's content does not impact reproductibility. It can be empty and the issue will still occur.
      • The document is correctly inserted in the collection despite the exception.
      • Doing a 2nd identical findAndModify query doesn't create the exception.
      • The issue doesn't occur on mongo 2.0.7

      Error:

      The shell outputs the following when the exception occurs :

      	"lastErrorObject" : {
      		"errmsg" : "need to login",
      		"ok" : 0
      	},
      	"errmsg" : "exception: assertion src/mongo/db/../bson/bsonobjbuilder.h:131",
      	"code" : 0,
      	"ok" : 0
      

      The stack trace is as follow (along with a couple of lines prior/after for context):

      Tue Nov 13 18:46:37 [conn3] run command test.$cmd { findandmodify: "testCollection", query: { foo: "bar" }, update: { $set: { bob: "john" } }, sort: { foo: 1.0 }, upsert: true, new: true }
      Tue Nov 13 18:46:37 [conn3] query test.testCollection query: { query: { foo: "bar" }, orderby: { foo: 1.0 } } ntoreturn:1 scanAndOrder:1 keyUpdates:0  nreturned:0 reslen:20 0ms
      Tue Nov 13 18:46:37 [conn3] update test.testCollection query: { foo: "bar" } update: { $set: { bob: "john" } } nscanned:1 nupdated:1 fastmodinsert:1 keyUpdates:0  13ms
      Tue Nov 13 18:46:37 [conn3] run command admin.$cmd { getlasterror: 1 }
      Tue Nov 13 18:46:37 [conn3] command admin.$cmd command: { getlasterror: 1 } ntoreturn:1 keyUpdates:0  reslen:63 0ms
      Tue Nov 13 18:46:37 [conn3]  test Assertion failure !e.eoo() src/mongo/db/../bson/bsonobjbuilder.h 131
      0x1047c7c0b 0x1047a5c8c 0x104466f47 0x104519cfd 0x10454b89b 0x10454c91b 0x10454d004 0x10460acae 0x10460b43c 0x1045c0b25 0x10445bb02 0x1047be23d 0x1047f92c5 0x7fff8ef0a742 0x7fff8eef7181 
       0   mongod                              0x00000001047c7c0b _ZN5mongo15printStackTraceERSo + 43
       1   mongod                              0x00000001047a5c8c _ZN5mongo12verifyFailedEPKcS1_j + 284
       2   mongod                              0x0000000104466f47 _ZN5mongo14BSONObjBuilder8appendAsERKNS_11BSONElementERKNS_10StringDataE + 375
       3   mongod                              0x0000000104519cfd _ZN5mongo16CmdFindAndModify3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 2613
       4   mongod                              0x000000010454b89b _ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRNS_14BSONObjBuilderEb + 91
       5   mongod                              0x000000010454c91b _ZN5mongo11execCommandEPNS_7CommandERNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 2907
       6   mongod                              0x000000010454d004 _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 1076
       7   mongod                              0x000000010460acae _ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 46
       8   mongod                              0x000000010460b43c _ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 1436
       9   mongod                              0x00000001045c0b25 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 1349
       10  mongod                              0x000000010445bb02 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 206
       11  mongod                              0x00000001047be23d _ZN5mongo3pms9threadRunEPNS_13MessagingPortE + 1645
       12  mongod                              0x00000001047f92c5 thread_proxy + 229
       13  libsystem_c.dylib                   0x00007fff8ef0a742 _pthread_start + 327
       14  libsystem_c.dylib                   0x00007fff8eef7181 thread_start + 13
      Tue Nov 13 18:46:37 [conn3] command test.$cmd command: { findandmodify: "testCollection", query: { foo: "bar" }, update: { $set: { bob: "john" } }, sort: { foo: 1.0 }, upsert: true, new: true } ntoreturn:1 keyUpdates:0 locks(micros) w:15909 reslen:182 15ms
      

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            ovaillancourt Olivier Vaillancourt
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: