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

Shell's special query path for exhaust queries or "$cmd" queries trips tassert on negative limit

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • QE 2022-06-13
    • 15

      The shell currently has two separate paths for running find commands: the DBCommandCursor path which is implemented primarily in the JavaScript layer, and the C++ native path. Historically, the former was used for find commands and the latter was used for legacy OP_QUERY find. However, OP_QUERY find is no longer supported by the shell. The only cases in which the C++ path currently get used are for queries against the "$cmd" namespace and for exhaust queries.

      The C++ native path is broken when given a negative limit. This trips a tassert in the shell. Examples:

      MongoDB Enterprise > db.$cmd.foo.find().limit(-3)
      {"t":{"$date":"2022-06-08T14:47:06.679Z"},"s":"E",  "c":"ASSERT",   "id":4457000, "ctx":"js","msg":"Tripwire assertion","attr":{"error":{"code":5746103,"codeName":"Location5746103","errmsg":"DBClientCursor limit must be non-negative"},"location":"{fileName:\"src/mongo/client/dbclient_cursor.cpp\", line:669, functionName:\"operator()\"}"}}
      Error: DBClientCursor limit must be non-negative
      
      MongoDB Enterprise > db.$cmd.foo.findOne()
      {"t":{"$date":"2022-06-08T14:47:11.579Z"},"s":"E",  "c":"ASSERT",   "id":4457000, "ctx":"js","msg":"Tripwire assertion","attr":{"error":{"code":5746103,"codeName":"Location5746103","errmsg":"DBClientCursor limit must be non-negative"},"location":"{fileName:\"src/mongo/client/dbclient_cursor.cpp\", line:669, functionName:\"operator()\"}"}}
      Error: DBClientCursor limit must be non-negative :
      DBQuery.prototype._exec@src/mongo/shell/query.js:149:40
      DBQuery.prototype.hasNext@src/mongo/shell/query.js:302:10
      DBCollection.prototype.findOne@src/mongo/shell/collection.js:267:17
      @(shell):1:13
      
      MongoDB Enterprise > db.c.find().addOption(DBQuery.Option.exhaust).limit(-10)
      {"t":{"$date":"2022-06-08T14:47:31.846Z"},"s":"E",  "c":"ASSERT",   "id":4457000, "ctx":"js","msg":"Tripwire assertion","attr":{"error":{"code":5746103,"codeName":"Location5746103","errmsg":"DBClientCursor limit must be non-negative"},"location":"{fileName:\"src/mongo/client/dbclient_cursor.cpp\", line:669, functionName:\"operator()\"}"}}
      Error: DBClientCursor limit must be non-negative
      

      The work for this ticket is to fix the shell so that these queries work as expected, which will resolve the linked build failure.

      As far as I can tell, there is no reason to use the C++ path for "$cmd" namespaces. I think this relates to some old behavior around pseudo-commands which is no longer relevant. We should just use the normal DBCommandCursor path in this case.

      We still need to use the C++ native path for exhaust queries. (Note, however, that SERVER-20770 and SERVER-58491 suggest consolidating the two code paths in the shell.) A good fix for this problem would be to add support for exhaust in the new DBClientBase::find() API and then migrate the shell from DBClientBase::query_DEPRECATED() to DBClientBase::find().

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            mindaugas.malinauskas@mongodb.com Mindaugas Malinauskas
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: