Details
-
Improvement
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
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
- is related to
-
SERVER-61385 Migrate most callers of legacy 'DBClientBase::query()' API to modern 'find()' API
-
- Closed
-