[CXX-1579] Calling cursor.begin() multiple times while it is pending will cause an exception Created: 09/May/18  Updated: 27/Oct/23  Resolved: 09/May/18

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: 3.2.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: John Murphy Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

If a tailable cursor is opened against a collection, and it does not return any results on initial 3 calls to cursor.begin() it will fail with Cannot advance a completed or failed cursor.: generic server error.

This is due to this line of code which will advance the cursor without checking to see if there are any results available.

Suggest that the code be changed to something like:

    if (libmongoc::cursor_more(_cursor->_impl->cursor_t) &&
            libmongoc::cursor_next(_cursor->_impl->cursor_t, &out)) {
        _cursor->_impl->doc = bsoncxx::document::view{bson_get_data(out), out->len};
    } else if ...



 Comments   
Comment by John Murphy [ 09/May/18 ]

According to the tailable cursor documentation:

Tailable cursors may become dead, or invalid, if either:

  • the query returns no match.

Therefore marking this as Working as Designed.

Generated at Wed Feb 07 22:03:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.