[BUG] npm `node_modules` directory in bad state after `ECONNRESET` error
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.1k
- Forks
- 4.7k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 19
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
For reasons unknown, running npm install (or related commands) on my machine with npm 8.x results in frequent ECONNRESET errors. (I recently upgraded from node 12 / npm 6, which did not have these issues). I am NOT using a proxy.
I am not experiencing internet issues of any sort with anything else. I am using an internal npm server over a vpn, but others are not having issues. No amount of system restarts, router restarts, or re-installs seems to help me. Regardless, this isn't this issue.
When a ECONNRESET error is seen, npm does not seem to retry the request internally. Given the intermittent issues I am seeing, I think retrying would allow the install to succeed.
Attempting to run npm install after a ECONNRESET issue is seen results in a ENOTEMPTY error like:
This requires a rm -rf node_modules to resolve. It seems the ECONNRESET error leaves stuff in a bad state.
UPDATE: The ECONNRESET is caused by our internal npm server occasionally running our of RAM. The issue with npm not handling the error correctly and getting into a bad state still stands.
Expected Behavior
- If an
ECONNRESETerror is seen, npm should retry the request internally at least once. - If an error is raised, error-handling should clean up any folder structures to allow for a retry to succeed
Steps To Reproduce
- Have something be borked somewhere in your network stack, triggering intermittent
ECONNRESETerrors - Run
npm installor a related command (doing a fresh install dramatically increases the chance of an error) - Observe an
ECONNRESETerror - Retry the
npm install, observe that there is aENOTEMPTYerror due to improper cleanup after theECONNRESETerror
Environment
- npm: 8.3.0
- Node: 16.13.1
- OS: macos 10.15.7
- platform: MBP
- npm config:
registry = "<PRIVTE_REGISTERY_URL_REDACTED>"
; node bin location = /Users/piercej/.nvm/versions/node/v16.13.1/bin/node
; cwd = /Users/piercej/code/representation-api
; HOME = /Users/piercej
; Run `npm config ls -l` to show all defaults.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with npm install under intermittent ECONNRESET conditions, then inspect the request retry and cleanup paths involved in the command. Done means an ECONNRESET is retried or handled cleanly, and a subsequent npm install does not fail with ENOTEMPTY.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100