[BUG] npx -y takes 70 s offline before running a cached package (about 5 min when packets are dropped)
维护者通常 2 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 67/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, node.js
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.jsstill fetches the manifest withpreferOnline: 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
- Online, run an MCP server once so it's cached:
npx -y @modelcontextprotocol/server-memory. - Make the registry unreachable, for example with
npm_config_https_proxy=http://proxy.invalid:8080for that command, or by disconnecting from the network. - Start it again with
npx -y @modelcontextprotocol/server-memoryand send aninitializerequest on stdin. The reply arrives after about 70 s. - Repeat with
--prefer-offlineornpm_config_fetch_retries=0: the reply arrives in about 0.4 s.
Environment
- npm: 11.2.0 (the same
preferOnline: truein 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.
- 主要语言
- JavaScript
- 星标
- 10.3k
- 派生
- 5k
- 平均合并
- 4 天 11 小时
- 30 天内合并 PR
- 26
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
npm/cli 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 2 天内回复
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endings可能已有人在做 @saruk-vedant 于 7 天前认领。 未关闭Bug Needs Triage Triage Requested
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
[BUG] npm pkg delete removes the first array item for a nonexistent property可能已有人在做 @drawliin 于 42 天前认领。 未关闭cmd:delete Priority 3
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 2 天内回复
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings logged可能重新可做 关联的 PR 已关闭且未合并。 未关闭Engineering Priority 1
难度 1/5 1 小时以内 新手友好度 80/100
维护者通常 2 天内回复
-
`npm audit signatures` does not report how many packages it skipped for want of registry keys可能已有人在做 @greenlincoln05 于 63 天前认领。 未关闭Priority 3
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
相似的 Issue
-
docs: add SECURITY.md vulnerability reporting policy可能已有人在做 @AK-Lmn 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 72/100
flisk-sh/linux2wasm#12 ·
维护者通常 1 天内回复
-
possible bug
难度 2/5 1-3 小时 新手友好度 84/100
Mintplex-Labs/anything-llm#7388 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 60/100
维护者通常 1 天内回复
-
v6: Minified bootstrap.min.css is missing header info可能已有人在做 @lazerg 今天认领。 未关闭bug build confirmed has-pr v6
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
documentation
难度 1/5 1 小时以内 新手友好度 88/100
githubnext/gh-aw-workshop#6332 ·
维护者通常 1 天内回复