fix(libnpmexec): fix lock compromise logic #8733
Open
+33
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix a race condition in
withLockwhere a slowfs.statcall could result in an ECOMPROMISED false positive. Due to the usage ofsetInterval, one callback could mutatemtimejust before an overlapping callback'sfs.statpromise has resolved, causing a mismatch. By switching tosetTimeout, 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.stathas 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
npx --yes jest --versionReferences
Fixes #8710