"EMFILE - too many open file" error
See original GitHub issueThis 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-fsand/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:
- Created a year ago
- Reactions:44
- Comments:23 (3 by maintainers)
Top Related StackOverflow Question
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-excludesandserverless-plugin-include-dependenciesplugins. This immediately resulted in a necessary not being included, but that issue appears to be specific to theknexORM library and is probably unrelated to the issue within serverless. Ultimately, that was resolved by manually importing a sub-dependency in my own project.Update: I got to the root of the issue. Here’s the full fix for NodeJS:
yarn add -D graceful-fs@4.2.6.node_modules/serverless/bin/serverless.jsand add this right afteruse strict;: