"EMFILE - too many open file" error

See original GitHub issue

Previous issue: #3249, #10706

This is a meta-issue to gather all reports about the following error:

EMFILE - too many open files error

This is a very tough issue to solve because it happens randomly. It is caused by having too many files open on the whole machine (not just the serverless process).

A possible root cause could be synchronous usage of the fs API. A solution might be to use graceful-fs and/or the async API to access the filesystem.

We use graceful-fs and reduced the use of sync calls in Serverless Framework to a minimum, but some plugins might not. We’re trying to identify which plugins might cause the issue.

Workarounds

This isn’t ideal, but it is possible to increase the limit of files open on Linux and macOS with ulimit (https://stackoverflow.com/a/21070580/245552), but not on Windows.

If you have information about more workarounds, please post them here and we’ll update the issue.

How to help?

  • Add a 👍 on this issue (so that we can estimate the impact)
  • Investigate if some plugins might benefit from using graceful-fs and/or async filesystem calls
  • Fill the following form and post it as a comment:
OS:
Serverless Framework version ('sls --version'):
Node version ('node --version'):
Plugins used:

Let’s try and see if there’s a pattern (e.g. a plugin that comes up often).

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:44
  • Comments:23 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
nunchukguncommented, Apr 7, 2022

Thank you for continuing to investigate this. After a bunch of digging, I was able to resolve my issue by using the serverless-plugin-common-excludes and serverless-plugin-include-dependencies plugins. This immediately resulted in a necessary not being included, but that issue appears to be specific to the knex ORM library and is probably unrelated to the issue within serverless. Ultimately, that was resolved by manually importing a sub-dependency in my own project.

1reaction
serg06commented, Oct 30, 2022

Update: I got to the root of the issue. Here’s the full fix for NodeJS:

  1. Run yarn add -D graceful-fs@4.2.6.
  2. Open up node_modules/serverless/bin/serverless.js and add this right after use strict;:
require('../../graceful-fs/graceful-fs').gracefulify(require('fs'));
Read more comments on GitHub >

github_iconTop Results From Across the Web

node and Error: EMFILE, too many open files - Stack Overflow
After a number of searches I found a work around for the "too many open files" problem: var requestBatches = {}; function batchingReadFile( ......
Read more >
EMFILE: too many open files, watch · Issue #923 - GitHub
i'm facing below issue while generating archive in xcode node:events:371 throw er; // Unhandled 'error' event ^ Error: EMFILE: too many open ......
Read more >
How to fix the: "EMFILE: too many open files, watch" error in ...
A quick guide to how I solved a confusing React Native error. ... How to fix the: "EMFILE: too many open files, watch"...
Read more >
How to Fix the 'Too Many Open Files' Error in Linux?
Very often 'too many open files' errors occur on high-load Linux servers. It means that a process has opened too many files (file ......
Read more >
Fixing the “Too many open files” Error in Linux - Baeldung
Learn about the Linux system limits placed on file descriptors in the context of understanding and resolving the "Too many open files" ...
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