FG
🛠️ Developer ToolsMicrosoft

[BUG] Npm opens many connections when installing

Freshabout 19 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] 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: [code block]

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Limit Concurrent Connections During Npm Install

Medium Risk

The high number of concurrent connections during 'npm install' is due to npm's default behavior which attempts to maximize throughput by opening multiple connections to download packages simultaneously. This can overwhelm package proxies and lead to performance degradation, especially when dealing with a large number of packages.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Set Maximum Concurrent Connections

    Modify the npm configuration to limit the number of concurrent connections. This can be done by setting the 'maxsockets' option, which controls the maximum number of concurrent connections to the registry.

    bash
    npm config set maxsockets 20
  2. 2

    Clear Npm Cache

    Before running the installation again, clear the npm cache to ensure that any previously cached connections do not affect the new settings.

    bash
    npm cache clean --force
  3. 3

    Run Npm Install

    After configuring the maximum sockets and clearing the cache, run the 'npm install' command again to observe the changes in connection behavior.

    bash
    npm install
  4. 4

    Monitor Network Load

    Use network monitoring tools to observe the number of connections being opened during the installation process. Ensure that the number of concurrent connections is now limited to the specified maximum.

    bash
    Use tools like Wireshark or built-in OS network monitors.

Validation

Confirm that the number of concurrent connections during 'npm install' is limited to the configured maximum (e.g., 20). Check the network load on your package proxy to ensure it is manageable and does not exceed expected thresholds.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsbugpriority-0release-10.x