Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Too many parallel network connections open while installation #7272

Closed
2 tasks done
ankurparihar opened this issue Mar 7, 2024 · 12 comments
Closed
2 tasks done
Assignees
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 10.x

Comments

@ankurparihar
Copy link

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

Hi,

For a project npm install opens nearly ~2100 connections in parallel, the same project installed via pnpm only takes about 18 concurrent connection.

This causes a huge bandwidth issue for our internal CI/CD pipelines.

Expected Behavior

Please provide a way to limit concurrent connection.

Steps To Reproduce

  1. In this environment
  • MacOS / Linux
  1. First clean cache
  • npm cache clean --force
  • pnpm store prune
  1. Run npm i / pnpm i in any project containing package.json
  2. in parallel run watch -n 0.2 "ss -tunap | wc -l" - to monitor open connections

Environment

  • npm: 10.2.4
  • Node.js: v20.11.1
  • OS Name: MacOS Sonoma 14.2.1 (23C71)
  • System Model Name: Macbook Pro
  • npm config:
; node bin location = /usr/local/bin/node
; node version = v20.11.1
; npm local prefix = /home
; npm version = 10.2.4
; cwd = /home
; HOME = /root
; Run `npm config ls -l` to show all defaults.
@ankurparihar ankurparihar added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Mar 7, 2024
@ankurparihar ankurparihar changed the title [BUG] <Too many parallel network connections open while installation> [BUG] Too many parallel network connections open while installation Mar 7, 2024
@ankurparihar
Copy link
Author

Update:

  • Node 16.20.2, NPM: 8.19.4 ~25 max concurrent connections
  • NODE: 18.19.1, NPM: 10.2.4 also makes ~2100 connections

It seems this was increased from Node 18

@ankurparihar
Copy link
Author

It seems maxsockets is also not being respected, setting this to a lower value like 10 or 1 didn't have any effect.

@mhdawson
Copy link

mhdawson commented Mar 7, 2024

I'm not sure if this is related, but we've seen some teams running into problems moving between versions of Node.js with npm 9 versus 10 and running out of file handles which sounds like it could be related.

@lukekarrys lukekarrys self-assigned this Mar 7, 2024
@lukekarrys lukekarrys added Priority 1 high priority issue and removed Needs Triage needs review for next steps labels Mar 7, 2024
@lukekarrys
Copy link
Contributor

Update:

  • Node 16.20.2, NPM: 8.19.4 ~25 max concurrent connections

  • NODE: 18.19.1, NPM: 10.2.4 also makes ~2100 connections

It seems this was increased from Node 18

Thanks for the report, I will take a look at this.

@ChristophLindemann
Copy link

@lukekarrys check out #7072 which has been open since December. It might have some more insights.

@ankurparihar
Copy link
Author

Thank you for the prompt response, let me know if I can do some help, even in testing and all.

@melroy89
Copy link

Update:

  • Node 16.20.2, NPM: 8.19.4 ~25 max concurrent connections
  • NODE: 18.19.1, NPM: 10.2.4 also makes ~2100 connections

It seems this was increased from Node 18

Thanks for the report, I will take a look at this.

That would be much appreciated, I'm using Node LTS (v20.11.1), which is using NPM v10.2.4. Where this problem is still present, and causing a lot of issues during CI/CD pipelines.

@silverwind
Copy link

Imho, it's definitely related to maxsockets having not effect in npm 10.

@dominicfraser
Copy link

@neelance commented something interesting in #7072

neelance
So... I went into the rabbit hole... It went very very deep... But I finally found the root cause!

npm-reqistry-fetch uses make-fetch-happen, see here.
make-fetch-happen uses minipass-fetch, see here.
minipass-fetch uses Node's builtin http/https, see here.
The maxSockets parameter gets passed through all these layers just fine, no issue here.
However, the implementation of http.Agent in Node.js is suboptimal: It checks for maxSockets here, but does not immediately increase the checked value. Instead it calls this.createSocket and assumes the function pushes to this.sockets synchronously. Typical risk for a race condition.
Now back up the stack again: make-fetch-happen uses @npmcli/agent, see here
@npmcli/agent uses agent-base, see here
agent-base subclasses http.Agent and overwrites createSocket with an implementation that is asynchronous, see here.
🫠

@neelance
Copy link

I added a workaround to #7072.

@silverwind
Copy link

Can we close this duplicate issue in favor of #7072?

@ljharb
Copy link
Contributor

ljharb commented Mar 17, 2024

Duplicate of #7072

@ljharb ljharb marked this as a duplicate of #7072 Mar 17, 2024
@ljharb ljharb closed this as not planned Won't fix, can't repro, duplicate, stale Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 10.x
Projects
None yet
Development

No branches or pull requests

9 participants