-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.6.1
-
Component/s: Client Side Encryption, Lambda
-
None
Customer via intercom has reported a bug in the source code for the libmongocrypt package
He connects MongoDB Atlas via AWS Lambda and he uses automatic Field Level Encryption. It basically works, but in about 30% of the function invocations he recieves random errors: Most of the time it is "Current topology does not support sessions" He is on 4.4 cluster with the current NodeJS driver 3.6. Sometimes he gets MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27020 as an error. If he deactivates automatic field level encryption everything works fine as expected.
He figured out that there is some sort of race condition in the client between spawning the mongocryptd process and connecting to the cluster. He checked our source code for the libmongocrypt package. While the code comment says that the lib will wait until the mongocryptd process is up, it is not what the code does: https://github.com/mongodb/libmongocrypt/blob/8530af06643daa28259e5830ce1dff22b6be326a/bindings/node/lib/mongocryptdManager.js#L65
There is a tiny bug in there. The code wait until the process is spawned, not until the process is ready. So there is a chance for race conditions where the client tries to connect but mongocryptd process is not ready.
Please look into it.