npm / npm/cli

[BUG] npm `node_modules` directory in bad state after `ECONNRESET` error

Open
#4,159 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
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:

Screen Shot 2021-12-10 at 10 37 32 AM

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 ECONNRESET error 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
  1. Have something be borked somewhere in your network stack, triggering intermittent ECONNRESET errors
  2. Run npm install or a related command (doing a fresh install dramatically increases the chance of an error)
  3. Observe an ECONNRESET error
  4. Retry the npm install, observe that there is a ENOTEMPTY error due to improper cleanup after the ECONNRESET error
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.