Skip to content

Fix Vitest Windows CI EPERM Hang - #995

Open
skoll43 wants to merge 45 commits into
mksglu:nextfrom
skoll43:fix/vitest-eperm-hang
Open

Fix Vitest Windows CI EPERM Hang#995
skoll43 wants to merge 45 commits into
mksglu:nextfrom
skoll43:fix/vitest-eperm-hang

Conversation

@skoll43

@skoll43 skoll43 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Fix Vitest kill EPERM Hang on Windows (Leaky File Locks)

Problem

On Windows environments, the CI and local npm test runs frequently hang at the very end of the test suite during the Vitest worker teardown phase, throwing a kill EPERM or Timeout terminating forks worker error.

While the majority of the codebase correctly uses in-memory databases (:memory:) or explicit store.cleanup() hooks, several integration test files were instantiating file-backed SessionDB and ContentStore instances (better-sqlite3) locally within test() blocks and never closing them.

Because Vitest runs in a worker pool, these unclosed C++ native file locks persist at the OS level. When Vitest attempts to terminate the worker pool, Windows rejects the termination or directory cleanup due to the active locks, causing the deadlock.

Solution

Introduced a scope-safe teardown pattern to the 5 anomalous test files:

  • tests/core/search-project-filter.test.ts
  • tests/integration/omp-plugin.test.ts
  • tests/integration/commit-message-symmetry.test.ts
  • tests/integration/cross-project-attribution.test.ts
  • tests/integration/seed-parity-coverage.test.ts

Pattern:
Added a module-level tracking array (const activeDBs = []) to each file. Instances are pushed to the array upon creation, and an afterEach() hook iterates through the array to forcefully call .close() (and .cleanup()) on every instance before clearing the array.

Verification

  • Verified locally that running the leaky tests (e.g., search-project-filter.test.ts) in isolation now tears down instantly (~2 seconds) on Windows without hanging.
  • The afterEach hook guarantees closure even if the test fails or times out.

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.

1 participant