serverless: sls deploy causes 'EMFILE - too many open files' error
This is a Bug Report
Description
- Since upgrading to 1.7.0 the serverless deploy stage is causing an
EMFILE - too many open files error - This does not occur in 1.6.1, and updating package.json to reference 1.6.1 resolves this issue
- This does not occur with node 6.9.5, however it is completely reasonable to expect that development teams would be working with the same version of Node as used on the AWS Lambda runtime, and this is exactly the setup we have on our CI servers.
- Stack Trace: build 15-Feb-2017 08:25:13 build 15-Feb-2017 08:25:13 > redacted deploy redacted build 15-Feb-2017 08:25:13 > sls deploy “–stage” “dev” “–region” “eu-west-1” “–profile” “default” build 15-Feb-2017 08:25:13 build 15-Feb-2017 08:25:14 build 15-Feb-2017 08:25:14 WARNING: You are running v1.7.0. v1.8.0 will include the following breaking changes: build 15-Feb-2017 08:25:14 - Will replace IamPolicyLambdaExecution resource with inline policies -> https://git.io/vDilm build 15-Feb-2017 08:25:14 - “sls info” will output the short function name rather than the lambda name -> https://git.io/vDiWx build 15-Feb-2017 08:25:14 build 15-Feb-2017 08:25:14 You can opt-out from these warnings by setting the “SLS_IGNORE_WARNING=*” environment variable. build 15-Feb-2017 08:25:14 build 15-Feb-2017 08:25:17 Serverless: Wrote .env file to redacted build 15-Feb-2017 08:25:17 Serverless: Packaging service… error 15-Feb-2017 08:25:42 events.js:141 error 15-Feb-2017 08:25:42 throw er; // Unhandled ‘error’ event error 15-Feb-2017 08:25:42 ^ error 15-Feb-2017 08:25:42 error 15-Feb-2017 08:25:42 Error: EMFILE: too many open files, open ’ redacted\node_modules\dynogels\test\schema-test.js’ error 15-Feb-2017 08:25:42 at Error (native)
Commit b0df37673bd3a1fac11ccbfa3eb48e3626c0acb1 looks like a potential cause.
Additional Data
- Serverless Version 1.7.0
- Windows Version Windows Server 2012 R2
- Node Version 4.3.2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 40 (17 by maintainers)
Got the same problem on our build servers. 1.7.0 is de facto unusable - changing system settings on the build infrastructure is IMHO not an option at all to “fix” a software issue. @pmuens This would be a strong reason to provide a 1.7.1 bugfix release outside of the standard release cycle.
I verified that 1.8.0 now works again without emitting the EMFILE error.
Ok. Finally found a way to reproduce it.
Here are the steps:
serverless.ymlandpackage.jsonfile:cdinto the service and install the dependencies:Note: Those are randomly picked packages
I find it kinda frustrating that the when searching for an solution for this problem on a new setup(Node 14.17.1, Framework 2.72.2) i’m only finding “Closed”-issues? How can this be closed when it is still happens?
Edit: Downgrading from 2.72.2 to 2.72.1 solved the issue in my case, however, i feel that this is caused purely by luck and that the issue might resurface at any point… most likely when i need to fix something urgent in production 😦
2nd edit: Sure thing! I got it working for a while, but then it suddenly started with “Too many files” again…it seems random as i feared…
For those that are still running into this. Check out https://stackoverflow.com/questions/8965606/node-and-error-emfile-too-many-open-files
Thanks for the updates.
The other quick “solution” would be to go back to
readFileSync(which is used e.g. in v1.5.1). However the downside is that large services will eat up a bunch of memory and so CI / CD systems might suffer (that’s why we’ve changed it tocreateReadStreamin the first place).Other suggestions how to solve this problem are highly welcomed!
Regarding my experiences with the webpack plugin: With the graceful-fs fix I experienced that the serverless process will just exit to the shell after printing “Packaging service…”. Not exactly sure what’s happening there exactly.
It is not a new issue, it’s been an issue for the last couple of years. I highly doubt it can/will be solved because i create a new issue. I mostly added my comment for “google history”. I’m not even sure it’s an issue with Serverless, NodeJS or my setup somehow, but it’s still broken and it seems nondeterministic somehow, which makes error reports like mine almost useless…
@scott-martin This is on the “urgent” list and will be fixed soon!
There’s already the
graceful-fsPR out there (#3259) which resolves the issue. However it introduces other issues with e.g. the usage of the serverless webpack plugin (@HyperBrain discovered this).Not sure if there’s another way right now to fix this in an elegant way.
This error has officially made serverless UNUSABLE. its been ongoing for the longest time and down grading is NOT an option. all solutions online are only posted for OSX and nothing is out there for windows. Unusable Framework
@fsobh i fixed it by exluding the heavier node_modules dependencies in
same for me. Node 7.5 failing with same error after running
serverless deploy --noDeployThis happens with Node v6.9.5 too. I can reproduce with the
node:6.9.5Docker image. Using--ulimit nofile=20:20didn’t work for me though. NPM would fail installing the dependencies and Serverless itself. I launched the container without the option,cd /app && npm install && npm install -g serverless, thenulimit -n 1024, thensls deploy --noDeploy.@stevecaldwell77 On Windows here so no such luck
FYI, I ran into this issue too and worked around it by upping my open file limit (I’m on OSX) to 65536 as described here:
http://blog.mact.me/2014/10/22/yosemite-upgrade-changes-open-file-limit