Skip to content

fix(tests): retry EBUSY when removing test DB dirs on Windows - #515

Merged
DavidBabinec merged 1 commit into
CoreBunch:mainfrom
tahayusab:fix/windows-test-teardown-retry
Sep 11, 2026
Merged

fix(tests): retry EBUSY when removing test DB dirs on Windows#515
DavidBabinec merged 1 commit into
CoreBunch:mainfrom
tahayusab:fix/windows-test-teardown-retry

Conversation

@tahayusab

@tahayusab tahayusab commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Refs #284 (the EBUSY half that remained after DbClient.close() landed in #327).

What changed

createTestDb() cleanup now retries fs.rm with exponential backoff (15s budget) when it hits EBUSY.

Why

On Windows the OS keeps the SQLite WAL/SHM siblings locked for a while after the last handle closes (asynchronous release, sometimes extended by real-time antivirus scans of freshly written files). fs.rm then fails with EBUSY and server test files (accountSecurity, authStepUp, collabRelay, chatImageHandler, ...) show teardown failures even though every assertion passed. Measured locally: the lock can be held 15s+ after db.close().

Retrying is safe because every handle in the process is already closed; on POSIX the first attempt always succeeds so Linux CI is unaffected.

Verification (local, Windows, bun 1.3.14)

  • bun run build - pass
  • bun run lint - pass
  • bun test src/tests/server/accountSecurity.test.ts - 16/16 pass
  • bun test src/tests/ai/chatImageHandler.test.ts - 9/9 pass
  • full suite: 6735 tests, 244 -> 155 failing (remainder are EBUSY holds beyond the 15s budget on this machine + publisher tests that rm their own dirs)
  • Linux reference run (native container disk): 0 EBUSY failures

On Windows the OS keeps the SQLite WAL/SHM siblings locked for a while
after the last handle closes (asynchronous release, sometimes extended
by real-time antivirus scans of freshly written files). fs.rm then
fails with EBUSY and flaky teardown failures appear across the server
test suite. Retrying with exponential backoff (15s budget) is safe —
every handle in the process is already closed — and on POSIX the first
attempt always succeeds, so CI is unaffected.
@tahayusab
tahayusab force-pushed the fix/windows-test-teardown-retry branch from 178f1a9 to 3ecd87e Compare September 10, 2026 09:36
@DavidBabinec
DavidBabinec marked this pull request as ready for review September 11, 2026 11:43
@DavidBabinec
DavidBabinec merged commit 93ddd41 into CoreBunch:main Sep 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants