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

compareTopologyVersion issue with useBigInt64

    • 0
    • Not Needed
    • 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?

      Code:
      ```
      const client = new mongo.MongoClient(uri, { });
      const db = client.db('test',

      { useBigInt64: true }

      );
      ```

      Error:
      ```
      TypeError: Cannot convert a BigInt value to a number
      ?, in isNaN
      File "/app/node_modules/.pnpm/bson@6.6.0/node_modules/bson/lib/bson.cjs", line 908, col 13, in Long.fromNumber
      if (isNaN(value))
      File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server_description.js", line 185, col 88, in compareTopologyVersion
      const newCounter = bson_1.Long.isLong(newTv.counter) ? newTv.counter : bson_1.Long.fromNumber(newTv.counter);
      File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server.js", line 356, col 60, in shouldHandleStateChangeError
      return (0, server_description_1.compareTopologyVersion)(stv, etv) < 0;
      File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server.js", line 225, col 21, in Server.handleError
      if (shouldHandleStateChangeError(this, error)) {
      File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server.js", line 287, col 14, in Server.decorateCommandError
      this.handleError(error, connection);
      File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server.js", line 172, col 28, in Server.command
      throw this.decorateCommandError(conn, cmd, finalOptions, commandError);
      File "node:internal/process/task_queues", line 95, col 5, in process.processTicksAndRejections
      File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/operations/find_and_modify.js", line 91, col 24, in FindOneAndUpdateOperation.execute
      const result = await super.executeCommand(server, session, cmd);
      File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/operations/execute_operation.js", line 126, col 16, in executeOperation
      return await operation.execute(server, session);
      ```

      I'm not sure what exactly triggers this. It happens often in production, but from reading the stack trace, it's only if something else triggered some kind of error on the connection.

      The core issue appears to be that the code assumes the counter is either a number or Long, but useBigInt64 causes it to be a bigint instead.

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            ralf@journeyapps.com Ralf Kistner
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: