Fix Vitest Windows CI EPERM Hang - #995
Open
skoll43 wants to merge 45 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Vitest
kill EPERMHang on Windows (Leaky File Locks)Problem
On Windows environments, the CI and local
npm testruns frequently hang at the very end of the test suite during the Vitest worker teardown phase, throwing akill EPERMorTimeout terminating forks workererror.While the majority of the codebase correctly uses in-memory databases (
:memory:) or explicitstore.cleanup()hooks, several integration test files were instantiating file-backedSessionDBandContentStoreinstances (better-sqlite3) locally withintest()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.tstests/integration/omp-plugin.test.tstests/integration/commit-message-symmetry.test.tstests/integration/cross-project-attribution.test.tstests/integration/seed-parity-coverage.test.tsPattern:
Added a module-level tracking array (
const activeDBs = []) to each file. Instances are pushed to the array upon creation, and anafterEach()hook iterates through the array to forcefully call.close()(and.cleanup()) on every instance before clearing the array.Verification
search-project-filter.test.ts) in isolation now tears down instantly (~2 seconds) on Windows without hanging.afterEachhook guarantees closure even if the test fails or times out.