-
Type: Task
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: Lambda
NODE-3810 Description
What problem are you facing?
Heartbeat failures are causing MongoDB Nodejs to disconnect, then reconnect, on a warm container. Yes, I am using best practices to connect to MongoDB within Lambda, connection outside of handler, etc. Have been using AWS Lambda and MongoDB for 3 years, warm invocations always using an existing connection. This reconnection issue started around August 5th 2021. It is intermittent and does not always occur.
I am just guessing here, but the heartbeat failing seems to be the center of the issue. It seems to occur when a warm function is invoked again and the time between invocation is longer than the heartbeat duration determining failure.
Perhaps when a heartbeat is sent at the end of an invocation, and fails at the start of the next invocation, this failure is due to the time elapsed between invocations. Maybe the randomness of reconnections is due to a heartbeat being sent at the end of an invocation, and is not "processed" until the next invocation, and the duration between is causing the heartbeat time elapsed to trigger a heartbeat failure?
With older MongoDB driver versions I was able to toggle unified topology. Interestingly, if unified topology is turned off, the disconnect/reconnect issue goes away. However, then initial connection timeouts sporadically occur.
Unified Topology = True
- Frequent new connections between invocations on the same warm Lambda container. (bad).
- No initial connection timeouts. (good)
- Total connections on Atlas Cluster approaching limits . (bad)
Unified Topology = False
- No new connections between invocations on the same warm Lambda container. (good).
- Initial connection timeouts sporadically occur on cold start without any pattern. (bad)
- Total connections on Atlas Cluster normal. (good)
What driver and relevant dependency versions are you using?
I am using Mongoose to connect to MongoDB and have tested and used several versions, all with the same results. I was excited when 4.2.1 was released, but unfortunately it didn't solve the issue.
MongoDB NodeJS 3.6.8 and 4.2.1 (depending on Mongoose version)
MongoDB Atlas cluster 4.4.10
NodeJS 12.x and 14.x
Steps to reproduce?
I suppose the only way to reproduce is to connect to MongoDB via AWS Lambda function (NodeJS 12.x or 14.x), send invocations on a warm container with random durations between. Log serverHeartbeatStarted, serverHeartbeatSucceeded and serverHeartbeatFailed events.
- is depended on by
-
NODE-3810 AWS Lambda: MongoDB heartbeat failure.
- Closed