Open rschick opened 8 months ago
I'm not familiar with the npm codebase, but I was able to fix this issue by adding retries here: https://github.com/npm/cacache/blob/main/lib/put.js#L69. I'd be happy to submit a PR if you think this is a viable approach.
I'm not familiar with the npm codebase, but I was able to fix this issue by adding retries here: https://github.com/npm/cacache/blob/main/lib/put.js#L69. I'd be happy to submit a PR if you think this is a viable approach.
What about updating the library to use graceful-fs
instead of fs
? I think that essentially does the same thing – adds a backoff to prevent EMFILE
errors.
I don't know if there is a performance reason cacache
is using the lower-level fs
API – it does have ~29 million weekly downloads and needs to be "really fast".
I fixed this issue by using fs-extra
package instead of fs/promises
.
It uses graceful-fs
internally and provides patched functions with support for promises.
This fixes EMFILE, also EAGAIN and potential problems with antivirus software.
There is also example of custom implementation using only p-limit package https://github.com/prismicio/slice-machine/pull/1192.
Is there an existing issue for this?
Current Behavior
EMFILE error may be thrown during
npm install
, depending on the allowed file descriptors and the state of the cache before the install. An example error:Expected Behavior
npm install
should succeed.Steps To Reproduce
(The error happens reliably with nuxt, but it's not related to nuxt, you can use other packages and get the same result.)
ulimit -Hn 128
(It's possible to get the error with a higher ulimit, but using a low value helps to reliably reproduce the error)rm -rf /<home-dir>/.npm/_cacache/
rm -rf node_modules
npm install
(Reset ulimit using
ulimit -Hn unlimited
)Environment