[BUG] npx -y takes 70 s offline before running a cached package (about 5 min when packets are dropped)

Aperta
#10,320 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@evilive3000 ci sta già lavorando.

Dal 20/11/2026.

  • #10322 di @evilive3000 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
67/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js
Ambito
backend, cli

Direzione di ricerca

Start with workspaces/libnpmexec/lib/index.js and inspect the getManifest call that uses preferOnline: true; compare its behavior with --prefer-offline and the reported cache fallback. Reproduce with a cached package and an unreachable registry, then check that npx starts it promptly while preserving normal online behavior. The issue gives timings and reproduction steps but does not name a test file.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Triage Requested
Is there an existing issue for this?
  • I have searched the existing issues. #7295 is related: npx re-checks the registry on every run. This issue is about how long that check takes when the registry can't be reached.
This issue exists in the latest npm version
  • I measured on npm 11.2.0. On npm 12.2.3, workspaces/libnpmexec/lib/index.js still fetches the manifest with preferOnline: true (line 30).
This is not just a request to bump a dependency for a CVE
  • This is not solely a request to bump a dependency for a CVE
Current Behavior

npx -y <package> always fetches the package's manifest from the registry, even when the package is already in the npx cache: getManifest in libnpmexec passes preferOnline: true. When the registry can't be reached, npm's fetch retries run first, and only then does npx fall back to the cached copy and start the package. That takes 70 s. When packets are dropped (a captive portal or a firewall), it takes about 5 minutes.

This matters for MCP servers in particular. Most MCP client configurations start their servers with npx -y <server>, so offline every agent start waits over a minute for each server, and clients with shorter startup timeouts give up first.

Measured with @modelcontextprotocol/server-memory, already in the npx cache: the time from starting it until it answers the MCP initialize request over stdio. To make the registry unreachable without changing any configuration, I set npm_config_https_proxy for the command only.

Registry unreachable (5 alternating rounds) Median Range
npx -y 70,408 ms 70,382–70,478
npm_config_fetch_retries=0 npx -y 433 ms 372–567
npx -y --prefer-offline 379 ms 351–400
Other failures (one run each) npx -y --prefer-offline
DNS fails (proxy proxy.invalid) 70.4 s 0.38 s
Connection refused (proxy 127.0.0.1:9) 70.7 s 0.55 s
Packets dropped (proxy 10.255.255.1:8080) 295.5 s 0.34 s

With the registry set to registry.invalid (no proxy), it fails after 70.2 s, so a DNS failure gets the same retries. That run fails only because nothing is cached under that URL.

Expected Behavior

When the package is in the cache and the registry can't be reached, npx runs the cached version quickly. For example, it could skip retries for DNS failures and refused connections during this freshness check, or give the check a short timeout.

Steps To Reproduce
  1. Online, run an MCP server once so it's cached: npx -y @modelcontextprotocol/server-memory.
  2. Make the registry unreachable, for example with npm_config_https_proxy=http://proxy.invalid:8080 for that command, or by disconnecting from the network.
  3. Start it again with npx -y @modelcontextprotocol/server-memory and send an initialize request on stdin. The reply arrives after about 70 s.
  4. Repeat with --prefer-offline or npm_config_fetch_retries=0: the reply arrives in about 0.4 s.
Environment
  • npm: 11.2.0 (the same preferOnline: true in 12.2.3)
  • Node.js: 22.14.0
  • OS Name: macOS 14.2.1 (Apple silicon)
  • System Model Name: Apple silicon Mac
  • npm config: defaults

Measured with wits. I used an AI assistant to help investigate and write this up; the numbers are from the runs described above.

Lingua principale
JavaScript
Stelle
10.3k
Fork
5k
Merge medio
4g 11h
PR unite (30g)
26

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di npm/cli

Tutte le issue di npm/cli

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.