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

Mongos leaves cursor open for legacy OP_QUERY find with ntoreturn of 1

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.4.0-rc0
    • Affects Version/s: 3.2.9, 3.3.14
    • Component/s: Querying, Sharding
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Query 2016-10-10
    • 0

      In the legacy OP_QUERY find protocol, an ntoreturn of 1 is special because it requires the server to close the cursor after retrieving the result. The new mongos query path introduced in 3.2 fails to handle this case correctly. This can be reproduced with the following script, run through a shell with --readMode legacy:

      db.c.drop();
      db.c.insert({_id: 1});
      db.c.insert({_id: 2});
      
      var cursor = db.c.find().limit(1);
      if (cursor.hasNext()) { cursor.next(); }
      
      // After retrieving the first result, serverStatus shows that
      // mongos has left its cursor open.
      db.serverStatus().metrics.cursor;
      
      // If you ask the cursor whether it has another result,
      // the shell will issue a getMore. In response to the getMore,
      // mongos will close the cursor and return an empty batch.
      cursor.hasNext();
      db.serverStatus().metrics.cursor;
      

      The mongod query path implements this correctly. If you run the above script directly against a mongod, the initial serverStatus will show that the mongod does not have an open cursor.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: