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

Subsequent requests on cached connection returning cursor session error

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.4.1
    • Affects Version/s: None
    • Component/s: None
    • 3
    • Not Needed

      Upgrading my Vercel-hosted app to the new MongoDB driver (4.0) has introduced sporadic errors like this:

      MongoServerError: Cursor session id ([session hash])is not the same as the operation context's session id (none)

      I have fiddled with the MongoDB caching and connection script as recommended by Vercel/Next https://github.com/vercel/next.js/blob/canary/examples/with-mongodb/lib/mongodb.js but the issue continues.

      I'm not clear enough on what the changes are in the new driver that might be introducing this, but it's fixed by rolling back to 3.6.10.

      The issue seems to happen when a request is made more than 30 seconds after an identical query from the same Node.js function.

      Is there a new/improved way of caching connections recommended for serverless functions?

      Full error looks like this:
      2021-08-01T05:24:18.728Z bd23cb98-d3a7-4c7f-b439-a86991d87661 ERROR MongoServerError: Cursor session id ([long hash]) is not the same as the operation context's session id (none)
      at MessageStream.messageHandler (/var/task/node_modules/mongodb/lib/cmap/connection.js:470:30)
      at MessageStream.emit (events.js:375:28)
      at processIncomingData (/var/task/node_modules/mongodb/lib/cmap/message_stream.js:108:16)
      at MessageStream._write (/var/task/node_modules/mongodb/lib/cmap/message_stream.js:28:9)
      at writeOrBuffer (internal/streams/writable.js:358:12)
      at MessageStream.Writable.write (internal/streams/writable.js:303:10)
      at TLSSocket.ondata (internal/streams/readable.js:726:22)
      at TLSSocket.emit (events.js:375:28)
      at addChunk (internal/streams/readable.js:290:12)
      at readableAddChunk (internal/streams/readable.js:265:9) {
      operationTime: new Timestamp(13, 1627795458),
      ok: 0,
      code: 13,
      codeName: 'Unauthorized',
      '$clusterTime': {
      clusterTime: new Timestamp(13, 1627795458),
      signature:

      { hash: new Binary(Buffer.from("3116bf7b7da884c3b7f5b607f1380f3a38f45a4e", "hex"), 0), keyId: new Long("6951405380324818948") }

      }
      }

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            mongodb@catchy.nz David Buck
            Neal Beeken
            Votes:
            7 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: