Skip to content

fix(libnpmexec): fix lock compromise logic - #8733

Merged
owlstronaut merged 1 commit into
npm:latestfrom
jenseng:fix-ecompromised-on-windows
Nov 18, 2025
Merged

owlstronaut merged 1 commit into
npm:latestfrom
jenseng:fix-ecompromised-on-windows

Conversation

@jenseng

@jenseng jenseng commented Nov 14, 2025 •

Copy link
Copy Markdown
Contributor

Fix a race condition in withLock where a slow fs.stat call could result in an ECOMPROMISED false positive. Due to the usage of setInterval, one callback could mutate mtime just before an overlapping callback's fs.stat promise has resolved, causing a mismatch. By switching to setTimeout, we ensure that we don't have overlapping callbacks and incorrect values.

Additionally bump the stale threshold higher, to reduce the likelihood of another caller taking over a seemingly-stale-but-actually-active lock. Under Windows in particular, fs.stat has been observed to sometimes take over 20 seconds, so we should err on the side of a higher threshold before we judge a lock as stale. The minor potential downside is that we might wait longer before taking over a stale lock, but lock takeover is already a very exceptional case (i.e. it would typically only happen if another process was SIGKILLed while holding the same lock)

Testing Notes

  • Added a new test to cover this scenario
  • Verified the failure and the fix via one-off GHA workflow that does npx --yes jest --version

References

Fixes #8710

@jenseng
jenseng requested a review from a team as a code owner November 14, 2025 18:43
@jenseng jenseng changed the title fix(libnpmexec): improve lock compromise logic fix(libnpmexec): fix lock compromise logic Nov 14, 2025
@jenseng

jenseng commented Nov 14, 2025 •

Copy link
Copy Markdown
Contributor Author

Under Windows in particular, fs.stat has been observed to sometimes take over 20 seconds

I suspect this may not be due to any underlying bugs in fs.stat or anything like that. Rather it seems likely that in certain cases (e.g. installing a very large package like jest in a Window VM) that arborist can block the event loop for multiple seconds.

@owlstronaut owlstronaut left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thanks for the contribution!

@owlstronaut
owlstronaut merged commit 3439a89 into npm:latest Nov 18, 2025
@github-actions github-actions Bot mentioned this pull request Nov 18, 2025
Bewinxed added a commit to Bewinxed/cawco that referenced this pull request Oct 19, 2026
…ith node: no session waits on npx's lock

npx 11.19.1 takes <cache>/_npx/<hash>/concurrency.lock on every start
(libnpmexec index.js `withLock(lockPath, ...)`), waits on it forever,
and removes it only from signal-exit, which a SIGKILL never runs; the
next npx waits until the lock is `staleThreshold = 60_000` ms old, the
MCP SDK's own initialize timeout. Boundaries end sandboxes with SIGKILL
and every workspace shares one npm cache, so one killed session held
every other session's browser tool for a minute. npm 12.2.0 keeps it
(npm/cli#8733 accepts the wait).

The fleet sync now installs each npx row's package at its exact version
(`latest` and ranges read from the registry at the sync) with npm into
<data>/cawco/fleet-mcp/<name>@<version>, through a staging dir renamed
whole, and every harness launches its bin with node. A failed install
makes the row failed with npm's own sentence; an npx line that is not
one registry package is refused in words. npm is npm's, never a Bun
alias (the 1e63e6e rule, moved from npx to npm). The install dir is
read-only to every workspace (fleetSyncedPaths).

An install no row names retires once the sessions live when it was
superseded have ended and no process holds its held file open: node
preloads it (--require) and it opens itself, since a server may rename
its process (chrome-devtools-mcp sets process.title) and XNU omits a
code-restricted process's environment from ps -E. Looked at again each
60 s while in use, and at every session's end.

browser-shield and browser-cutover pin no npm cache; browser-gate PUTs
the fleet row and launches the entry the sync wrote. New spec
fleet-mcp-install.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] npm exec fails with ECOMPROMISED with Node 24 on Windows

2 participants