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

AWS Lambda: MongoDB heartbeat failure.

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.5.0
    • Affects Version/s: 4.2.1
    • Component/s: Lambda
    • 5
    • Not Needed

      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

      1. Frequent new connections between invocations on the same warm Lambda container. (bad).
      2. No initial connection timeouts. (good)
      3. Total connections on Atlas Cluster approaching limits . (bad)

      Unified Topology = False

      1. No new connections between invocations on the same warm Lambda container. (good).
      2. Initial connection timeouts sporadically occur on cold start without any pattern. (bad)
      3. 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.

       

        1. march22-reproduction-logs.json
          166 kB
        2. Screenshot 2022-03-10 at 12.57.27.png
          Screenshot 2022-03-10 at 12.57.27.png
          102 kB
        3. Screenshot 2022-03-10 at 12.57.45.png
          Screenshot 2022-03-10 at 12.57.45.png
          889 kB

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            ryanwoodmiami@gmail.com Ryan Wood
            Durran Jordan
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: