Having more than one iterator per cursor violates mongoc lifecycle constraints

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 3.1.0
    • Affects Version/s: None
    • Component/s: Implementation
    • None
    • None
    • Major Change
    • None
    • None
    • None
    • None
    • None
    • None

      Given a single cursor, iterator construction and iteration result in the construction of bsoncxx::document::view objects wrapping the bson_t pointer returned by a call to mongoc_cursor_next. However, the validity of this bson_t pointer is only until the next call to mongoc_cursor_next (see docs).

      Consider this example:

      auto cursor = db["fo"].find({});
      auto iter1 = cursor.begin();  // Calls mongoc_cursor_next().
      auto iter2 = cursor.begin();  // Calls mongoc_cursor_next().
      
      // At this point, iter1._doc violates the lifecycle constraints.
      
      iter1++;
      
      // At this point, iter2._doc violates the lifecycle constraints.
      

      In short, only the most recently iterated iterator ever has a valid bsoncxx::document::view.

              Assignee:
              David Golden
              Reporter:
              David Golden
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: