npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@samwen/lambda-emfiles

v1.1.1

Published

solve node AWS lambda EMFILE issue

Downloads

21,267

Readme

lambda-emfiles

A solution to node AWS lambda EMFILE issue. If you spot following errors in your lambda function logs:

  1. getaddrinfo EMFILE
  2. EMFILE, too many open files
  3. with ioredis, Failed to refresh slots cache
  4. with mongodb, MongoError: no connection available, MongoServerSelectionError

...

etc

Most likely, it is caused by exceeding the file descriptors limit of AWS lambda.

lambda-emfiles provides solution to the problem.

how to use

install

npm install @samwen/lambda-emfiles

in your lambda code

what does it do:

  1. report file descriptor leaks to help debug.
  2. prevent it. if the file descriptors will reach the max limit in next run, it exits the process.

detail of the issue and solution

AWS lambda process runs within a docker container in Amazon Linux environment. The maximum limit on file descriptors is 1000. Normally, it is very hard for a lambda function to exceed the limit.

However, the lambda process within the container may be reused for performance optimization.

This is the reason for most cases of exceeding file descriptors limit.

Here is how it happens:

A lambda function leaks 100 file descriptors each time. It will hit the limit in abut 10 runs.

The chance that the lambda process is reused 10 times is really low.

This is why the lambda runs OK for most of times.

But you can spot few errors caused by exceeding file descriptors limit after a while, it depends on how frequently the lambda is running and the concurrency level of the lambda.

The best solution to the problem is to fix file descriptor leakage. lambda-emfiles provides report for this.

It takes time to fix file descriptor leakage, specially it works most of times.

Alternatively, lambda-emfiles calls process.exit(1) when it predicts a deficit of file descriptors in next run. Once the process is gone, it will not reused.

Tunning of parameters: max_emfiles_needed and exit_process

The 2 public methods come with default values for max_emfiles_needed and exit_process. The default values should work for most scenarios.

max_emfiles_needed: is the estimated max file descriptors will open in the same time.

exit_process: if it is true, it instructs lambda-emfiles to call process.exit(1), when it sees a deficit of file descriptors.