[CDRIVER-2093] mongoc_cursor_is_alive and mongoc_cursor_more incorrect querying an empty collection Created: 22/Mar/17 Updated: 03/May/17 Resolved: 29/Mar/17 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | libmongoc |
| Affects Version/s: | 1.6.0 |
| Fix Version/s: | 1.7.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | David Golden | Assignee: | David Golden |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
On a server using find commands, a query on an empty collection returns a cursor that returns incorrect values from mongoc_cursor_is_alive and mongoc_cursor_more after successive calls to mongoc_cursor_next. The attached code has a loop like this:
On a 2.6 mongod, the (correct) results are as follows:
Note that "is_alive" and "more" are true before the first call to "next". The call to "next" returns null, indicating exhaustion. In the second loop iteration, both "is_alive and "more" are false, indicating that the user should not call "next". When "next" is called, an error occurs. Now look at the output of the same loop on mongod 3.2:
In this case, even though iteration 1 had "next" return null, loop iteration 2 has "is_alive" and "more" true and the second call to "next" does not return an error. Iteration 3 finally has "is_alive" false, but oddly, still has "more" true. This time, the call to "next" returns an error. I believe the mongoc_cursor_is_alive error is caused at least in part by these lines, which reset cursor->done because the empty response from the execution of the find command sets done but not end_of_event (whatever that is). I believe the further problems of mongoc_cursor_more are also caused by end_of_event not being set. mongoc-cursor-cursorid.c does not provide a more function, causing mongoc_cursor_more to fall back to _mongoc_cursor_more, which checks end_of_event. |
| Comments |
| Comment by Githook User [ 27/Mar/17 ] |
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@emptysquare.net'}Message: Merge pull request #430 from xdg/
|
| Comment by Githook User [ 27/Mar/17 ] |
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@emptysquare.net'}Message: Merge pull request #430 from xdg/
|
| Comment by Githook User [ 27/Mar/17 ] |
|
Author: {u'username': u'xdg', u'name': u'David Golden', u'email': u'xdg@xdg.me'}Message: |