question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I need to figure out why an aws lambda is hanging

See original GitHub issue

I can’t add the flag --expose-internals to the call, is there any other way I can figure out what is hanging open?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
SET001commented, Mar 27, 2019

in my case I was using sequelize orm and I have to call await sequelize.close() at the end of each lambda. Setting context.callbackWaitsForEmptyEventLoop to false does not help in my case.

1reaction
justinmchasecommented, Feb 8, 2018

@yoshuawuyts Thanks.

In case anyone comes here asking similar questions in the future, after finally digging deep enough through the docs, I found this which solved the issue for me finally:

callbackWaitsForEmptyEventLoop

The default value is true. This property is useful only to modify the default behavior of the callback. By default, the callback will wait until the Node.js runtime event loop is empty before freezing the process and returning the results to the caller. You can set this property to false to request AWS Lambda to freeze the process soon after the callback is called, even if there are events in the event loop. AWS Lambda will freeze the process, any state data and the events in the Node.js event loop (any remaining events in the event loop processed when the Lambda function is called next and if AWS Lambda chooses to use the frozen process). For more information about callback, see Using the Callback Parameter.

For my case simply setting this to false early in my lambda allowed it to actually close without hanging when I called the callback:

context.callbackWaitsForEmptyEventLoop = false
example() // function that hangs open a socket or fd
callback() // will now call process.exit() for you safely

Obviously closing all of your unmanaged resources properly is the ideal way to solve this issue but this is a pretty effective sledgehammer approach when that becomes tricky.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Lambda function retry and timeout issues when ...
To troubleshoot the retry and timeout issues, first review the logs of the API call to find the problem. Then, change the retry...
Read more >
AWS Lambda hangs between invocations - Stack Overflow
I think the culprit is "Reserved concurrency: 1". The SQS --> Lambda part involves an invisible middle man called event source mapping which ......
Read more >
codepipeline.putJobSuccessResult() Hanging when Invoking ...
The first run through should work fine. Then assign the Lambda to the VPC and subnets, then run the pipeline again and see...
Read more >
Interesting story about how we solved a 'socket hang up' issue ...
Q: OK I know we have X-ray enabled, can we find more details there? ... logs for the lambda function, it looks like...
Read more >
Debugging AWS Lambda Timeouts - Lumigo
Finding the root cause of the timeout ... There are many reasons why a function might time out, but the most likely is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found