Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-4738

Do not resume after change stream cursor is closed

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: