Repository navigation
test(helpers): wait out a busy store delete instead of failing an unrelated test - #458
Conversation
…elated test removeStore closed this process's lock connections and then called rmSync with five 20 ms retries. On the Windows runner that was still not enough: a lock connection inside a section that is still running is deliberately left open, because closing it would give up a lock its writer believes it holds, so closeAllLockDatabases skips it. Windows then refuses the delete, and the red test is whichever one happened to be tearing down. Observed on the Windows job for PR 457: `EBUSY: resource busy or locked, rm 'C:\...\osi-capture-avail-ETFah7'` from remove-store.ts:19 through the harness afterEach, in a capture-availability test whose own assertions had all passed. removeWhileBusy now runs the delete with a doubling wait up to a 2 s budget. A delete that is still busy after the budget is reported on stderr naming the root, the code and the attempts, and abandoned: the directory lives in the OS temporary tree, which the runner reclaims, while a red test on an unrelated assertion is not reclaimable. An error that is not a held handle still throws immediately, so a wrong delete stays loud. The branches are driven through an injected remover in test/store/temp-store-fixture.test.ts, because Linux and macOS both delete a file another descriptor still has open — a test that waited for the real thing would assert nothing off Windows.
WhollyMindless
left a comment
There was a problem hiding this comment.
I checked the same-process holder described in the PR on Windows with Bun 1.4.4 at 0084d75. In a fresh temp store, I entered withStoreLock, had its callback await a 45 ms timer, then called removeStore while the callback was pending. Teardown warned after 9 attempts and 1,975 ms of backoff. The directory still existed and the holder was still pending. In the control, awaiting the same holder before calling removeStore deleted the directory immediately.
Bun.sleepSync keeps that callback from resuming between attempts, and closeAllLockDatabases() only runs before the first attempt, when it skips the in-use connection. The warning does keep the test green. If reclaiming this kind of store during teardown is intended, the retry needs to yield to the holder and close newly idle connections before retrying. If deferring cleanup is intentional, could teardown skip the two-second wait for a known same-process holder? The injected-remover test misses this distinction because its outcome advances with the attempt count.
|
Would a small follow-up patch for the same-process case be useful? I can make the shared test teardown yield between delete attempts so the lock holder can finish, then close newly idle connections before retrying. I’d include a Windows regression test with a real |
… it out The review on #458 measured the first version on Windows and was right on all three counts. A pending `withStoreLock` callback needs the event loop, and `Bun.sleepSync` owns the loop, so the retry window could never free the handle: 9 attempts, 1,975 ms, directory still present, holder still pending. The control — awaiting the holder first — deleted immediately. `closeAllLockDatabases` also ran once, before the first attempt, so a connection that went idle mid-wait was never closed. Two teardowns now, because the two callers differ: - `removeStore` stays synchronous. It asks `heldLockSectionsUnder` first: with a section running in this process the outcome is already decided, so it reports at once and spends no wait. Without one, the handle is external or lingering and the backoff is the right tool. - `removeStoreAsync` awaits between attempts and closes idle connections before each retry, which is what actually reclaims a store whose section is still running. `withTempStore`'s `afterEach` uses it. `heldLockSectionsUnder(dir)` is a new seam in src/store/lock.ts beside `heldLockDatabases`: the connections whose section is running, under one directory. `closeAllLockDatabases` already skips those, and now a caller can see why before deciding whether waiting can help. The tests no longer advance on an attempt count. The lock section is a real `withStoreLock`, and only the OS rule is injected — Linux and macOS delete a file another descriptor still has open, so the refusal cannot be produced portably. That makes the distinction assertable everywhere: the async teardown yields, the holder finishes, the store goes; the synchronous one gives up with the holder still pending and no sleep taken.
|
All three points confirmed against the code, and fixed in b321d92 — no patch needed, though the measurement is what made this actionable. The defect exactly as you described it. Two teardowns now, because the two callers genuinely differ:
The detection is a new seam beside On the tests — agreed, and that was the weakest part of the first version. The lock section is now a real
Plus the mechanics kept under injected seams: gap sequence Gate green locally at b321d92: comment policy, typecheck, 1627 unit tests, 37 e2e. — identified as an AI Assistant |
WhollyMindless
left a comment
There was a problem hiding this comment.
Verified the fix at b321d92 on native Windows with Bun 1.4.4. I reran the original 45 ms withStoreLock case through both public teardown helpers, using the real filesystem. Sync teardown returned in 1 ms with one warning and the holder still pending. Async teardown let the holder finish and removed the directory in 77 ms without a warning. That resolves the behavior I reported.
|
🎉 This PR is included in version 0.33.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What failed
The Windows job on PR 457 went red on one test whose own assertions had all passed:
capture availability tag > a control character in a candidate does not reach the audit line raw— capture and logfmt code, nothing to do with the pull changes in that PR. A rerun passed. That is the shape of this bug: the red test is whichever one happened to be tearing down.Why
removeStoreclosed this process's lock connections and calledrmSyncwithmaxRetries: 5, retryDelay: 20— about 100 ms. Two things beat that:closeAllLockDatabasesskips any connection withinUse > 0, because closing it would give up a lock its writer still believes it holds, and that silently drops the exclusion the lock exists to provide.EPERMas well asEBUSYwhen a child is merely mapped. macOS and Linux delete it either way, which is why nothing like this appears on the other runners.The change
removeWhileBusyruns the delete with a doubling wait (25 ms to 400 ms) against a 2 s budget. Outcomes:removeStore(dir, warn?)keeps its old call signature, so the harness and the 230-odd existing call sites are untouched.Deliberately not done
inUse > 0. It would make the delete succeed by breaking the lock's guarantee, and at teardown that guarantee is the last thing still being tested.Tests
Four cases in
test/store/temp-store-fixture.test.ts, driven through an injected remover: retried-then-clean, budget-spent-reports-and-returns-false, non-busy-throws-once, and a realremoveStoreon a quiet temp directory. A held handle cannot be produced on Linux or macOS — both delete a file another descriptor still has open — so a test that waited for the real thing would assert nothing off Windows.Merge gate green at 0084d75: comment policy, typecheck, 1597 unit tests, 35 e2e.
— identified as an AI Assistant