test(resolution): close graphs and connections, and always remove the temp project - #1786
Open
bompus wants to merge 1 commit into
Open
test(resolution): close graphs and connections, and always remove the temp project#1786bompus wants to merge 1 commit into
bompus wants to merge 1 commit into
Conversation
… temp project On Windows this file leaked 171 temp directories per run and failed 4 tests, both from the same cause: things that hold the SQLite database open outlive the code that removes their directory. afterEach removed tempDir only in the else branch of \if (cg)\, and cg is describe-scoped and never reset, so from the first test that assigns it every later test kept its directory. destroy() is a deprecated alias for close(): it releases the database but does not remove the project, so removal cannot be its alternative -- uninitialize() is the method that removes. Removal is now unconditional. That alone turns the silent leak into EPERM, because five DatabaseConnection.open calls were never closed and four nested tests removed their own tempProject while the outer cg still held it open. Each connection is now closed once its rows are materialised, and each nested finally closes the graph before removing its directory. Measured on Windows 11 with TEMP redirected to a private directory: before, 171 leaked directories and 4 failed / 196 passed; after, 0 leaked directories and 200 passed. Fixes colbymchenry#1777.
This was referenced Sep 8, 2026
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.
Fixes #1777.
On Windows,
__tests__/resolution.test.tsleaks 171 temp directories per run and fails 4 of its 200 tests. Both come from the same thing: something still holds the SQLite database open when the code that removes its directory runs.Measured
Windows 11 Pro 26200, Node 24 (the bundled runtime), vitest 2.1.9,
TEMPredirected to a private directory for the vitest process so concurrent work on the machine could not contaminate the count.main(7be699c)The four failures on
mainare pre-existing, not introduced here:Three changes
1.
afterEachremoves the project on every test. It removedtempDironly in theelsebranch ofif (cg), andcgisdescribe-scoped and never reset — so from the first test that assigns it (theCodeGraph.initaround line 1105) onward, every later test kept its directory.The reason the
elselooked reasonable is worth stating:destroy()is a deprecated alias forclose(). It releases the database and leaves the project on disk;uninitialize()is the method that removes it. So theifbranch was never cleaning up anything, and making removal its alternative meant removal almost never ran.2. Five
DatabaseConnection.opencalls are closed. None of them were. Making the removal unconditional immediately converts the silent leak intoEPERM, so these have to be fixed in the same change — a second connection to the same database keeps a handle on the directory. Each is now closed once its rows are materialised, before the assertions that use them.3. Four nested tests close their graph before removing their own project. These create their own
tempProject, assign the outercg, and remove the directory in afinallythat runs before the outerafterEachclosescg. The graph is now closed inside thatfinally.Note on the removal no longer being silent
afterEachnow lets a failed removal throw rather than swallowing it. That is deliberate: the swallowed failure is what let this run unnoticed, and it was hiding a real second defect (the unclosed connections), not just noise.force: true, maxRetries: 5covers Windows releasing handles slightly afterclose()returns.Related: #1722 was closed as "tests leak file handles into their temp projects: 24 fail with EPERM on Windows". This is the same underlying behaviour in this file, where it manifested as a silent leak instead of a failure.