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

Change stream error receives TypeError

    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Use Case

      As a developer
      I want use the change stream without receiving type errors
      So that it works like 6.7.0

      Repro code

      const resumeToken = get_the_resume_token()
      const changeStream = collection.watch(
          [
             ...the pipeline does a $match and a $project
          ],
          {
            fullDocument: 'updateLookup',
            resumeToken // NOTE: in our scenario this is undefined!
          }
      )
      
      changeStream.on('change', changeStreamChangeEventHandler)
      changeStream.on('error', async(error) => {
          log.error({ error, code: error?.code }, 'changeStream error') // here we see the TypeError
          throw new Error('unexpected error, restart service') // we decide to crash on error (there is actually more logic to it but it would not be interesting for this repro.
      })
      

       

      The log seen in the `error` handler is the following:

      {
          "level": 50,
          "time": 1719911469235,
          "pid": 6,
          "hostname": "tenant-overview-84d6f88f57-62g6h",
          "error": {
              "type": "TypeError",
              "message": "(responseType ?? responses_1.MongoDBResponse).make is not a function",
              "stack": "TypeError: (responseType ?? responses_1.MongoDBResponse).make is not a function
                  at Connection.sendWire (/home/node/app/node_modules/mongodb/lib/cmap/connection.js:243:80)
                  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
                  at async Connection.sendCommand (/home/node/app/node_modules/mongodb/lib/cmap/connection.js:280:24)
                  at async Connection.command (/home/node/app/node_modules/mongodb/lib/cmap/connection.js:313:26)
                  at async Server.command (/home/node/app/node_modules/mongodb/lib/sdam/server.js:167:29)
                  at async AggregateOperation.executeCommand (/home/node/app/node_modules/mongodb/lib/operations/command.js:73:16)
                  at async AggregateOperation.execute (/home/node/app/node_modules/mongodb/lib/operations/aggregate.js:86:16)
                  at async executeOperation (/home/node/app/node_modules/mongodb/lib/operations/execute_operation.js:136:16)
                  at async ChangeStreamCursor._initialize (/home/node/app/node_modules/mongodb/lib/cursor/change_stream_cursor.js:81:26)
                  at async ChangeStreamCursor.cursorInit (/home/node/app/node_modules/mongodb/lib/cursor/abstract_cursor.js:471:27)"
          },
          "msg": "changeStream error"
      }

       

       

      The affected line causes the make is not a function TypeError

      responseType ?? responses_1.MongoDBResponse).make is not a function

       

      My guess is that we are either incurring in a falsy (but not nullish) responseType OR an unexpected responseType that doesn't fit the MongoDBResponseConstructor type.

       

      I couldn't do further debugging on my own.

      User Impact

      • At the moment we can't upgrade the driver without incurring in this issue, rolling back to v6.7.0 makes the application work.

      Dependencies

      none

      Unknowns

      • How to properly debug/test this issue to submit a PR on my own, I think I've figured out what is going on and have a possible proposal but I can't be sure.

      Acceptance Criteria

      Implementation Requirements

      none

      Testing Requirements

      none

      Documentation Requirements

      none

      Follow Up Requirements

      none

        1. node_6249.mjs
          2 kB
        2. Screenshot 2024-07-03 alle 10.02.48-1.png
          Screenshot 2024-07-03 alle 10.02.48-1.png
          126 kB
        3. Screenshot 2024-07-03 alle 10.02.55.png
          Screenshot 2024-07-03 alle 10.02.55.png
          245 kB

            Assignee:
            Unassigned Unassigned
            Reporter:
            federico.maggi@mia-platform.eu Federico Maggi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: