Skip to content

[BUG] Npm opens many connections when installing #7072

Closed

Description

@Larsjep

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

My project needs around 2000 packages. When running "npm install" it starts out by opening 2000 connections and then when all the connections are open it downloads 1 package on each connection.

Is this intended?, because it causes a quite high load on our package proxy. Is there a way to limit the number of connections?

With npm 9.9 it only uses 18/20 connections.

Expected Behavior

"npm install" only opens a few connetions to the package server.

Steps To Reproduce

  1. Clear cache
  2. npm install or npm ci

Environment

  • npm: 10.2.5
  • Node.js: 18.19.0
  • OS Name: Windows 11
  • System Model Name:
  • npm config:
registry = "http://fosspackages/npm/default-npm/"
save-exact = true
save-prefix = ""

; node bin location = C:\Users\lj\.nvm\versions\node\v18.19.0\bin\node.exe
; node version = v18.19.0
; npm local prefix = C:\work\Dexter\web-client
; npm version = 10.2.5
; cwd = C:\work\Dexter\web-client
; HOME = C:\Users\lj
; Run `npm config ls -l` to show all defaults.

Activity

  1. Larsjep commented on Dec 12, 2023

    @Larsjep
    Author

    I noticed that there is a config option called maxsockets. But the default is 15 and
    npm config get maxsockets also returns 15.
    So if this should limit the number of connections it doesn't seem to work in npm 10.x.

  2. MartinFalatic commented on Dec 20, 2023

    @MartinFalatic

    @Larsjep Just curious what npm config get agent shows. Supposedly if that's set, maxsockets will be ignored in npm-registry-fetch.

    Could also be that's something that's buried in NPM and is somehow overridden in some other way, but it caught my eye when I searched the org for maxsockets.... might also help narrow down the problem at least.

  3. Larsjep commented on Dec 20, 2023

    @Larsjep
    Author

    @MartinFalatic npm config get agent returns undefined

    I have also looked in the code base, but I can't find anywhere it refers to the maxsockets settings.
    I can find it in the 9.x codebase, but the download part seem to radically changed in 10.x

  4. rosen-dimitrov commented on Dec 20, 2023

    @rosen-dimitrov

    +1 here.

    We are using self-hosted runners(ARC) on our own cluster and when using npm 10 we noticed a lot of dropped packets due to NAT ports exhaustion all coming from the arc runner executing npm install with npm 10. We have dynamic port allocation, which means that npm creates a lot of connections in a burst at the same time before the new ports can be allocated to the worker node running the runner pod.

    Npm 9 does not seem to have this issue. Looks an issue with the new @npmcli/agent http client introduced in npm 10.

    What is also interesting is that the workflow does not fail. npm seems to use whatever number of connections it managed to establish to install all packages.

  5. mirayashi commented on Dec 20, 2023

    @mirayashi

    Hello there,

    I would like to add that this is actually a bigger issue for very large projects (3000+ dependencies):

    • CPU and RAM usage is a lot higher than with npm 9
    • It is a lot slower than npm 9
    • npm install randomly fails with ECONNRESET and ETIMEDOUT errors (even more consistently on Windows), and seems to ignore most of .npmrc options (maxsockets, fetch-retries, etc)
  6. Th3S4mur41 commented on Jan 8, 2024

    @Th3S4mur41

    We're affected by the same issue...
    Our Jenkins CI is constantly failing to install private dependencies from GitHub (through our Proxy).

    Two potential workarounds are disabling the proxy (can't do that in corporate environment) or downgrading to npm 9

  7. silverwind commented on Feb 5, 2024

    @silverwind

    It seems the maxsockets option (default value 15) has no effect at all in npm@10, at least in situations where there is no proxy involved.

    When I run a npm install with around 1k dependencies inside a local VMWare VM, I'm consistently hitting a bug in VMWare where npm exhausts the CPU resources of vmnet-natd, which leads to npm hanging for minutes and finally terminating with random network errors. Downgrading to npm@9 completely resolves it.

  8. ajones513 commented on Feb 6, 2024

    @ajones513

    +1 here
    My company is having to hold back NPM 10 because of this issue when connecting to a private self-hosted registry. To help with our decision making, is there any indication when this might be triaged?

  9. greg-md commented on Feb 21, 2024

    @greg-md

    Same issue encountered on our vm lima. After upgrading to node v20 and npm v10, npm install freezes the entire vm. Downgrading to v9 fixed the issue.

  10. llimllib commented on Feb 23, 2024

    @llimllib

    We are seeing about half of our npm ci runs with npm version 10 on github actions fail; downgrading to npm version 9 speeds up install by about 45 seconds (2m45 -> 2m) and doesn't seem to fail at all.

    I can reproduce easily so please let me know if I can help debug this somehow

  11. dharmeshgordhan commented on Mar 8, 2024

    @dharmeshgordhan

    Potentially being looked at under #7272.

  12. melroy89 commented on Mar 10, 2024

    @melroy89

    My gitlab ci/cd is also very unstable due to this behavior. Often causing time outs due to the large amount of connections. Especially since I have some jobs running in parallel as well.

  13. 38 remaining items

  14. added a commit that references this issue on Jul 15, 2025
  15. added a commit that references this issue on Jul 16, 2025
  16. added a commit that references this issue on Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingPriority 0will get attention right awayRelease 10.x

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions