Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3163

Closing a ChangeStream does not terminate running next() calls, but invalidates them after they return data

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.5
    • Component/s: None

      In this exampe we filter the ChangeMessages rather strictly (only delete messages are allowed to be returned) and we start at a specific Entrypoint (for reproduction you need to specify an own entrypoint for this )
      ==> MongoDB will start to query the oplog for delete -changemessages. This can take some time, depending on the count of messages from starting-point to the first delete-message.
      ==> Before the first returning data (MongoDB is still querying) the ChangeStream is closed.

      Expected Behaviour:
      The Next-Call rejects with a "MongoError - Closed" instantly (or in "near" future at least).

      Actual Behaviour:
      The Next-Call rejects with a "MongoError - Closed" after quite some time (most likly after the initial query for the changestream is finished).

      Running the Script (with multiple Millions of Inserts between Entrypoint and Head of te Oplog):

      closed!
      default: 5:20.648 (m:ss.mmm)

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      import {MongoClient} from "mongodb";
      
      async function main(): Promise<void> {
        const client = await MongoClient.connect('mongodb://localhost:27017');
        const changeStream = client.watch([
          {$match: {operationType: 'delete'}}
        ], {
          resumeAfter: {_data: "82604F45E4000010452B022C0100296E5A1004B3CAF2964D1040069D88BCB4BD88DF91465A5F6964005A10049439945EFADA4818B6B5F9766ED13A310004"},
        });
      
        
        const next = changeStream.next();
        await changeStream.close();
        console.time();
        console.log("closed!");
        try {
          await next;
        } catch (err) {
          // Closed error will be thrown here
        } finally {    
          console.timeEnd();
        }
        process.exit();
      }
       main().catch(console.error);
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            haser@videmo.de Yannick Haser
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: