-
Type: Task
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
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:
}
}