Sporadic connection errors with AWS Lambda

XMLWordPrintableJSON

    • None
    • None
    • None
    • None
    • None
    • None
    • None

      We are experiencing random connection errors in our app when using AWS Lambda. We are experiencing the issues both for Node 10.x and Node 12.x, and are using mongo driver version 3.4.0 with the following settings:

      { 
         useUnifiedTopology: true,
         bufferMaxEntries: 0
      }
      

      This caused the lambda functions to randomly time out with error code 502.

      After changing connectTimeoutMS and socketTimeoutMS to 3000, we got the following error message from the sporadically failing connections.

      {
          "errorType": "TypeError",
          "errorMessage": "Cannot read property 'payload' of null",
          "stack": [
              "TypeError: Cannot read property 'payload' of null",
              "    at sendAuthCommand (/var/task/node_modules/mongodb/lib/core/auth/scram.js:244:47)",
              "    at _callback (/var/task/node_modules/mongodb/lib/core/connection/connect.js:320:5)",
              "    at Connection.errorHandler (/var/task/node_modules/mongodb/lib/core/connection/connect.js:336:5)",
              "    at Object.onceWrapper (events.js:286:20)",
              "    at Connection.emit (events.js:198:13)",
              "    at Connection.EventEmitter.emit (domain.js:448:20)",
              "    at TLSSocket.<anonymous> (/var/task/node_modules/mongodb/lib/core/connection/connection.js:353:10)",
              "    at Object.onceWrapper (events.js:286:20)",
              "    at TLSSocket.emit (events.js:198:13)",
              "    at TLSSocket.EventEmitter.emit (domain.js:448:20)"
          ]
      }
      

      We are caching our connection outside the lambda handler according to this blog post:

      https://www.mongodb.com/blog/post/optimizing-aws-lambda-performance-with-mongodb-atlas-and-nodejs

       

      Appreciate any help, Kind regards.

              Assignee:
              Matt Broadstone
              Reporter:
              Josefine Svegborn
              None
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: