[CDRIVER-4738] Do not resume after change stream cursor is closed Created: 02/Oct/23  Updated: 02/Oct/23

Status: Backlog
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Kevin Albertson Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to DRIVERS-2739 Add option to always use "startAfter"... Needs Triage

 Description   

Summary

Attempting to iterate a closed change stream results in the server error:

Attempting to resume a change stream using 'resumeAfter' is not allowed from an invalidate notification.

Proposed Change: Do not attempt to resume the change stream. Return an error message indicating the change stream is closed.

Consider: Compare behavior with other driver behavior when iterating a closed change stream cursor. Consider filing a DRIVERS ticket to specify a change stream must not attempt to resume after closed.

How to Reproduce

This branch includes a failing test to reproduce the error: https://github.com/mongodb/mongo-c-driver/compare/master...kevinAlbs:mongo-c-driver:changestream

Additional Background

The server signals a change stream is closed by responding with a 0 cursor ID. Example:

{ "cursor" : { "id" : 0, "ns" : "db.coll", "nextBatch" : [  ], "postBatchResumeToken" : { "_data" : "826516E9230000000F2B042C0100296F5A1004A9D70E866B784600A7165560BE721BF2463C6F7065726174696F6E54797065003C64726F70000004" } }, "ok" : 1.0, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1696000291, "i" : 23 } }, "signature" : { "hash" : { "$binary" : { "base64" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType" : "00" } }, "keyId" : 0 } }, "operationTime" : { "$timestamp" : { "t" : 1696000291, "i" : 23 } } }

The C driver mongoc_cursor_t returns this error when iterating a closed mongoc_cursor_t:

Cannot advance a completed or failed cursor

The Go driver ChangeStream checks for a cursor ID of 0. returns false to signal no events are returned, and does not attempt to resume or return an error.


Generated at Wed Feb 07 21:21:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.