Skip to content

Commit 0f6912c

Browse files
committed
docs: Windows review, bound every retry of the lock loops
The previous amendment bounded only the mkdir path. A dead-owner lock whose rename keeps failing with EPERM still looped forever: breakLock swallowed the error, continue went back to mkdir, EEXIST, breakLock, never reaching the deadline check or the sleep. A persistently failing stat had the same shape. W11 now prescribes the deadline check and back-off at the top of every retry, and reports the last permission error at the deadline. Measured on Windows: 0 of 24 contention runs fail, and both the deny-create parent and the rename-denied lock throw after the timeout instead of spinning.
1 parent e88ab40 commit 0f6912c

1 file changed

Lines changed: 49 additions & 18 deletions

File tree

‎dev-docs/runtime-migration/REVIEW-2026-10-21-windows.md‎

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,30 +195,61 @@ Windows consequence, MEASURED with the plans' code extracted verbatim: while one
195195

196196
PR 30's own 180-entry test and its "must not flake" Verification would fail on the Windows legs. A flaky test must not be parked in the `windows` known-failures list.
197197

198-
**Amendment:** on win32, treat `EPERM`/`EACCES`/`EBUSY` as transient, but only through a bounded retry that checks the deadline and sleeps.
199-
- Do not simply add these codes next to `EEXIST` in the `mkdir` catch. A *persistent* permission failure (no write access to the lock's parent) then falls through to the `mtime` stat, which finds no lock and `continue`s before both the deadline check and the sleep: a busy loop that never ends. MEASURED on a directory with a deny-create ACL: this version was still spinning after 10 s.
200-
- The `mkdir` site, in both plans (33's `acquireLock`, 30's `lockIndex` at 633):
201-
202-
```js
203-
const kTransient = process.platform === "win32" ? ["EPERM", "EACCES", "EBUSY"] : [];
204-
// ...
205-
try {
206-
fs.mkdirSync(lockDir);
207-
break;
208-
} catch (e) {
209-
if (kTransient.includes(e.code)) {
210-
if (Date.now() > deadline) throw e; // persistent: report the permission error
198+
**Amendment:** on win32, treat `EPERM`/`EACCES`/`EBUSY` as transient, and make *every* retry pass the deadline check and the sleep.
199+
200+
Two things make a per-site fix unsafe. First, the loop has several `continue` paths that skip the deadline check and the sleep: after a failed `mkdir`, after a `stat` that finds nothing (33's `mtime()` swallows every error; 30:639), and after `breakLock`. Second, a *persistent* permission failure looks just like a transient one. So swallowing these codes at any one site turns a permanent failure into a busy loop that never ends. MEASURED, with the codes swallowed at the sites but the loop otherwise unchanged:
201+
- a parent directory with a deny-create ACL: still spinning after 10 s (the `mkdir` path);
202+
- a dead-owner lock whose rename is denied: still spinning after 10 s (`breakLock` → `continue` → `mkdir` `EEXIST` → `breakLock`).
203+
204+
The loop shape, for 33's `acquireLock` and 30's `lockIndex` alike:
205+
206+
```js
207+
const kTransient = process.platform === "win32" ? ["EPERM", "EACCES", "EBUSY"] : [];
208+
const isTransient = (e) => kTransient.includes(e?.code);
209+
210+
async function acquireLock(lockDir) {
211+
const deadline = Date.now() + kLockTimeoutMs;
212+
let lastOwner, lastTransient;
213+
for (let attempt = 0; ; attempt++) {
214+
if (attempt > 0) {
215+
// every retry, whichever path asked for it, ends here
216+
if (Date.now() > deadline) {
217+
if (lastTransient) throw lastTransient; // persistent: report the permission error
218+
throw new Error(/* the plan's timeout message, naming lastOwner */);
219+
}
211220
await sleep(kLockRetryMs);
221+
}
222+
lastTransient = undefined;
223+
try {
224+
fs.mkdirSync(lockDir);
225+
break;
226+
} catch (e) {
227+
if (isTransient(e)) { lastTransient = e; continue; }
228+
if (e.code !== "EEXIST") throw e;
229+
}
230+
const m = mtime(lockDir);
231+
if (m === null) continue; // released between mkdir and stat, or stat failed
232+
lastOwner = readOwner(lockDir)?.owner; // readOwner: ENOENT or transient -> undefined
233+
const alive = lastOwner ? ownerAlive(lastOwner) : undefined;
234+
if (alive === false || (alive === undefined && Date.now() - m > kLockStaleMs)) {
235+
lastTransient = breakLock(lockDir); // returns the transient error it swallowed, else undefined
212236
continue;
213237
}
214-
if (e.code !== "EEXIST") throw e;
215238
}
216-
```
239+
// ... write the owner marker as in the plan
240+
}
241+
```
217242
218-
- The read and break sites (`readOwner`, `breakLock`, 30's `stat` `continue` at 639): treat the same codes as "not there yet". These paths reach the deadline check and the sleep, or go back to the `mkdir` above, so they stay bounded.
243+
- `breakLock` returns `undefined` on `ENOENT`, returns the error on a transient code, and throws anything else. In PR 30 the `stat` at 639 treats a transient code like `ENOENT`, recording it in `lastTransient`.
219244
- Both `rmSync` calls: `{ recursive: true, force: true, maxRetries: 10, retryDelay: 20 }`.
220-
- MEASURED for this version (PR 33's lock code, Node 24, 8 processes × 40 acquisitions): 0 of 24 runs failed. On the deny-create directory it throws the `mkdir` permission error once the timeout passes (3 s timeout in the test). PR 30's variant has the same structure; the measurements of an earlier version of this amendment (8/8 and 3/3 clean on Node, 5/5 on Deno) were taken without the bounded `mkdir` branch.
221-
- Record the rule once in PR 30's lock-ownership contract, since both PRs follow it.
245+
- Cost: one `kLockRetryMs` sleep after a successful `breakLock`, and after a lock released between `mkdir` and `stat`.
246+
- MEASURED for this shape (PR 33's lock code, Node 24, 3 s test timeout):
247+
- 8 processes × 40 acquisitions: 0 of 24 runs failed;
248+
- deny-create parent: throws the `mkdir` `EPERM` after the timeout;
249+
- rename-denied dead-owner lock: throws the `rename` `EPERM` after the timeout.
250+
251+
PR 30's variant has the same structure. The PR 30 measurements of the first version of this amendment (8/8 and 3/3 clean on Node, 5/5 on Deno) predate this loop shape.
252+
- Record the rule once in PR 30's lock-ownership contract, since both PRs follow it: "every retry of the acquisition loop passes the deadline check and the back-off; at the deadline, report the last permission error if there was one."
222253
223254
### W12 — `gen-tsconfig-paths --check` fails on every Windows checkout
224255

0 commit comments

Comments
 (0)