Skip to content

Commit 59145ce

Browse files
committed
Wait longer for rename lock contention to resolve
Anti-virus software on Windows can lock files for long periods of time, and graceful-fs was only waiting up to a second, and busy-looping during that wait, which has the potential to starve the locker of CPU.
1 parent 0798db3 commit 59145ce

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

polyfills.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,27 @@ function patch (fs) {
8080

8181
// on Windows, A/V software can lock the directory, causing this
8282
// to fail with an EACCES or EPERM if the directory contains newly
83-
// created files. Try again on failure, for up to 1 second.
83+
// created files. Try again on failure, for up to 60 seconds.
84+
85+
// Set the timeout this long because some Windows Anti-Virus, such as Parity
86+
// bit9, may lock files for up to a minute, causing npm package install
87+
// failures. Also, take care to yield the scheduler. Windows scheduling gives
88+
// CPU to a busy looping process, which can cause the program causing the lock
89+
// contention to be starved of CPU by node, so the contention doesn't resolve.
8490
if (process.platform === "win32") {
8591
fs.rename = (function (fs$rename) { return function (from, to, cb) {
8692
var start = Date.now()
93+
var backoff = 0;
8794
fs$rename(from, to, function CB (er) {
8895
if (er
8996
&& (er.code === "EACCES" || er.code === "EPERM")
90-
&& Date.now() - start < 1000) {
91-
return fs$rename(from, to, CB)
97+
&& Date.now() - start < 60000) {
98+
setTimeout(function() {
99+
fs$rename(from, to, CB);
100+
}, backoff)
101+
if (backoff < 100)
102+
backoff += 10;
103+
return;
92104
}
93105
if (cb) cb(er)
94106
})

0 commit comments

Comments
 (0)