Repository navigation
fix(lock): deadline rethrow = never saw the lock file, not last-probe-absent (#107) - #114
Conversation
…'last probe said absent' (abogartz#107)
|
The lone
If you want the family quieted rather than triaged per-run, the #105 shape (one test-level timeout pin per heavy window test, defaults untouched) is a five-minute PR covering both: |
abogartz
left a comment
There was a problem hiding this comment.
Verdict: APPROVED
Red leg reproduced exactly as described. I reverted only the deadline condition on this branch (!everSawHolder → absentStrikes > 0): consequence-2 test red (Expected: false, Received: true on threw), consequence-1 test red (ran true — the unguarded write), regression pin green both sides. Restored: 3/3 green. Full suite on macOS: 491 pass / 8 skip / 0 fail, tsc --noEmit clean.
The three-state probe is right, and your deviation from #107's literal wording is the correct reading. #107 said "set everSawHolder in the else branch" — doing that would set the flag on unknown probes too and re-open consequence 1 exactly (a blind filesystem would concede "unlocked-but-never-proven"). Setting it only on stat success makes the code match the comment's promise: "seen the lock file not even once". Your body called this out; I verified both branch tables (present/ENOENT/unknown × strikes/flag/deadline) land where the comment says.
Behavioral mapping, checked branch by branch: holder-entire-time → unchanged concession; seen-then-vanished → now concedes (the fix); only-ENOENT → 8-strike throw unchanged (ABSENT_THROW_STRIKES = 8, lock.ts:37); only-unknown → now throws firstErr at the deadline where the old code conceded — a deliberate tightening that only affects writers whose stat never once answered, which is the case the comment always said must not write. No call site regressed: one production caller (lock.ts:261, 5-arg, real clock), lockFileAbsent has zero remaining references.
Test construction: driving order matches the real loop (create → probe → steal-probe → deadline), the fake clock is bounded (the stepClock clamp makes a miscounted call order fail loudly rather than silently), and expect(events).toEqual(["timeout"]) guards against the scripted-clock trick where a far-future now could make stealIfStale steal a fresh lock — your vanishing-holder script closes that by unlinking before the steal probe. Honest bounds section appreciated.
Informational, not blocking
mock.module("node:fs/promises", …)is process-wide in Bun and never uninstalled — every test file that runs after this one in the samebun testprocess uses your wrapper for all fs access. It passes through for unscripted paths (and I verified the pre-mockrealcapture makes it non-circular), but it is permanent ambient state; worth a one-line comment saying so, since cross-file leakage is exactly how mystery flakes are born.test-windowsfailed once on your branch (the knownsupersede racing appendstorn-read flake — the same test #113 hit, and the one #70/#110 documents as baseline-red family on Windows); the rerun passed 491/0. I consider that the documented suite flake, not this change.
|
Added the one-line comment you suggested (f51d53a) - the mock block now says out loud that |
abogartz
left a comment
There was a problem hiding this comment.
Re-verified at f51d53a — APPROVED.
The commit is exactly the one thing the review asked for: a comment block at the mock site (test/lock-absent-holder.test.ts:20-23) stating that mock.module is process-wide, never uninstalled, and that the pass-through wrappers are permanent ambient state for every file that runs after. Nothing else changed (git diff b4f64b9..f51d53a: 4 added lines, one file).
Re-runs: tsc clean, lock-absent-holder.test.ts + lock.test.ts green (13/0/1 skip). The functional review at b4f64b9 (deadline rethrow = never-saw-the-file, everSawHolder gated on stat success, red legs reproduced both ways) stands; this closes the documentation note. Windows CI note also accepted — the torn-read family is the known baseline-red per #110's own docs, and the rerun passed.
|
Flake root-caused: this failure is #114 inheriting a test that landed with #113, not the lock change. Leg 1 — winner indeterminacy (correct code can go red). The harness bus ( Leg 2 — fixed-sleep completion race. Suggested fix (both legs, keeps the one-spend invariant as the red leg):
Filed as #117 ( |
|
🎉 This PR is included in version 0.14.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Confirmed closed from this side: #119's merge took the idle-broadcast legs out, and #114's merged history is clean (the lock change was the comment diff exactly as you root-caused). One datapoint for the record: the two-leg anatomy propagated to #118's new capture test by construction - both tests verdict on the evidence line rather than a sleep window (leg 2, same fix you specced here; a control test caught the read-too-early variant while it was being written), and the capture path there is single-setup compaction-driven behind a park seam, so leg 1's winner indeterminacy can't arise. The flake's paper trail runs clean end to end: #114 comment -> #117 -> #119. |
Fixes #107, exactly your prescription, with one precision about WHERE
everSawHoldergets set.The fix
lockFileAbsent's boolean quietly merges two different answers a probe can give - "stat succeeded" and "stat failed with something that isn't ENOENT" - and theelsebranch resets strikes on both. Three-state now:everSawHolder = true, strikes reset (as today)everSawHolderNOT setand the deadline branch becomes
if (!everSawHolder) throw firstErr. Setting the flag in theelsebranch as literally worded would let consequence 1's blind-probe writer keep proceeding unguarded - "set when a probe finds the lock" isstatsucceeding, and only that.Both consequences then close as designed: consequence 2's healthy vanish-at-deadline race falls through to the proceed-unlocked concession (
everSawHolderis what "this whole time" means); consequence 1's never-saw-anything writer finally meets the comment's promise at the deadline instead of the guard's absence.Pins
holdFileLockgrows a final optionalnow: () => number = Date.nowseam (exported; same "test seam" shape asresetHitThrottle/resetCaptureCooldowns, production call sites untouched) and amock.moduleonnode:fs/promisesintercepts ONLY the exact lock paths a test scripts - everything else passes through to the captured pre-mock functions. No pin depends on a wall-clock race:Expected: false, Received: trueonthrew- the rethrow ate an ordinaryLOCK_WRITE. Post-fix the concession runs:timeoutaudited, write lands unlocked.ran === truepre-fix (the unguarded write the comment forbids); post-fix the EPERM surfaces.Verified red (2 red / 1 green) by reverting only
src/lock.tswith the seam shimmed throughwithStoreLock; green 3/3 after.Honest bounds
concurrency.test.tstime-window tests under machine load and never reproduced: 4 further quiet full-suite Windows runs 486/0, 2 quiet main-baseline runs 483/0, both Linux legs green under both Buns. Reporting it rather than burying it.Verified
bun run test)tsc --noEmitandbiome lintclean. The pre-existing WindowsLOCK_WRITE/ACL tests (lock.test.ts10/10 incl. the icacls case) pass untouched - the 8-strike path, the steal path, and both timeout policies are behaviorally unchanged.assisted by Qwen3-flash-next