In load testing our AWS Lambda node function, we have got the following error message in our Cloudwatch logs:

2017-10-16T03:13:15.606Z    e95f33aa-b21f-11e7-8f1a-89b123118211    Error: ECONNREFUSED, Connection refused at Error (native)

This is the only line that is output and it only happens during load testing. With 10,000 requests, there are 200 of these errors and they happen towards the beginning of the load test.

Eventually everything succeeds because of retries but it would be nice to know what causes this. We have a try-catch block wrapping all of our code but it's not catching this error.

What causes this error and how can it be avoided or caught?

  • 2
    Showing your code would be helpful. – dashmug Oct 16 '17 at 4:38
  • Seems like a database connection error. – dashmug Oct 16 '17 at 4:38
  • There is no database - only S3 read and writes and publishing to an SNS topic. – Martimatix Oct 16 '17 at 5:10
  • 1
    Show your handler code so we know the possible reasons. – dashmug Oct 16 '17 at 5:11
  • 1
    Here's an excerpt from the log: pastebin.com/FU2BJgK5 We have instrumented the lambda script (deployed as single file with webpack) to debug the require step at function initialization. You see that it is started twice, which seems that the error is caught by the runtime and triggers a restart. Nasty. – Andrea Ratto Jun 22 '18 at 13:19

The aws SDK lib uses https to connect to various services like s3, sqs, etc. Since you are running performance tests, its likely to invoke new lambda containers in multiple (configured) subnets. I guess you are getting the ECONNREFUSED while sending connecting to outside world via HTTP/HTTPS protocols. My suggestion is to check the flow logs for the subnets that you are using for lambdas. Search for the 'REJECT OK' for 443 port and verify if the errors are originating for lambdas running in specific subnets.

|improve this answer|||||

Your Answer

