You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Too many parallel network connections open while installation #7272
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
In this environment
MacOS / Linux
First clean cache
npm cache clean --force
pnpm store prune
Run npm i / pnpm i in any project containing package.json
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.
changed the title [-][BUG] <Too many parallel network connections open while installation>[/-][+][BUG] Too many parallel network connections open while installation[/+]on 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.
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.
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.
🫠
Activity
[-][BUG] <Too many parallel network connections open while installation>[/-][+][BUG] Too many parallel network connections open while installation[/+]ankurparihar commentedon Mar 7, 2024
Update:
It seems this was increased from Node 18
ankurparihar commentedon Mar 7, 2024
It seems maxsockets is also not being respected, setting this to a lower value like 10 or 1 didn't have any effect.
mhdawson commentedon 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 commentedon Mar 7, 2024
Thanks for the report, I will take a look at this.
ChristophLindemann commentedon Mar 8, 2024
@lukekarrys check out #7072 which has been open since December. It might have some more insights.
ankurparihar commentedon Mar 8, 2024
Thank you for the prompt response, let me know if I can do some help, even in testing and all.
melroy89 commentedon Mar 10, 2024
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 commentedon Mar 15, 2024
Imho, it's definitely related to
maxsocketshaving not effect in npm 10.dominicfraser commentedon Mar 16, 2024
@neelance commented something interesting in #7072
neelance commentedon Mar 17, 2024
I added a workaround to #7072.
silverwind commentedon Mar 17, 2024
Can we close this duplicate issue in favor of #7072?
ljharb commentedon Mar 17, 2024
Duplicate of #7072