-
Type: Bug
-
Resolution: Gone away
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Lambda
What problem are you facing?
When using the MongoDB driver in a serverless environment (AWS Lambda) and caching the mongo client (as is suggested in the docs), the connection can randomly error out when not on its not fresh and has been idle for a few minutes.
The error message is
{ "errorType": "MongoServerError", "errorMessage": "Cursor session id (cab5f10b-3c28-4c54-9367-9f1139cf45d5 - YtQ++8mJ7yogtJevuYLyctK65Hs6eh6lahOEhcC+X3c=) is not the same as the operation context's session id (none)", "trace": [ "MongoServerError: Cursor session id (cab5f10b-3c28-4c54-9367-9f1139cf45d5 - YtQ++8mJ7yogtJevuYLyctK65Hs6eh6lahOEhcC+X3c=) is not the same as the operation context's session id (none)", " at MessageStream.messageHandler (/var/task/node_modules/mongodb/lib/cmap/connection.js:463: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)" ] }
Subsequent queries succeed without issue.
What driver and relevant dependency versions are you using?
Driver: 4.1.0
Cluster: 4.4.8 (Atlas)
Steps to reproduce?
This can be replicated trivially with any Lambda function that attempts to cache the mongo client.
I also tested this with an official MongoDB example for deploying Lambdas. If you follow the part of the guide which deploys a function to return movies (I used my own data) then call it, wait 5 minutes, and call it again, the function will error as described above.
I've also seen other reports of this online (like here).