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

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

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.0-rc0
    • Affects Version/s: None
    • Component/s: Internal Client
    • Fully Compatible
    • QE 2022-06-27, QE 2022-07-11
    • 64

      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.

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

              Created:
              Updated:
              Resolved: