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

Methods for iterating a DBClientCursor should assert that init() has been called

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 6.1.0-rc0
    • Internal Client
    • Fully Compatible
    • QE 2022-06-27, QE 2022-07-11
    • 64

    Description

      In order to fully initialize a DBClientCursor object, one must first call its constructor and then subsequently call DBClientCursor::init(). If the programmer makes a mistake and fails to call init(), the cursor can silently return no results rather than raising an error. Consider code like this:

      DBClientCursor cursor{...};
      while (cursor->more()) {
          BSONObj obj = cursor->nextSafe();
          // Do something with 'obj'.
      }
      

      This code is incorrect, since it fails to call init(). However, the call to cursor->more() simply returns false rather than throwing or tripping an assertion, so the bug could easily go undetected. We should improve the code to uassert() or possibly invariant() in this scenario.

      Attachments

        Issue Links

          Activity

            People

              catalin.sumanaru@mongodb.com Catalin Sumanaru
              david.storch@mongodb.com David Storch
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: