Repository navigation
test: close every database pool a test file opens - #849
Open
rahul05ranjan wants to merge 1 commit into
Open
rahul05ranjan wants to merge 1 commit into
rahul05ranjan wants to merge 1 commit into
Conversation
bun test runs server/tests in one process and a module-scope pool is never reaped, so PostgreSQL's 100-connection ceiling is a function of the files that have run, not imported, and the failure lands on whoever adds the next file (CopilotKit#785). Every createDatabase variable now gets a $client.close(): in the file's last top-level afterAll where one exists, or a new module-level afterAll registered after every other hook. A guard test keeps the pairing, and the sharded runner's 'import phase / never a reason to change source' sentences are corrected to what was measured. Fixes CopilotKit#785 Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
rahul05ranjan
requested review from
MikeRyanDev,
davidmckayv,
guidovizoso,
mxmzb and
tylerslaton
as code owners
October 27, 2026 12:50
This branch has not been deployed
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 #785.
What this changes
Three things, exactly as the issue proposes:
const <name> = createDatabase(variable now getsawait <name>.$client.close():afterAllcleanup — the close is its last statement, the idiomidentity-store.integration.test.tsuses;afterAll(only describe-scoped ones) — they gain a module-levelafterAllat the end of the file. Registered last, it runs last: Bun runsafterAllhooks first-registered-first, so the close follows every other hook's cleanup. A describe-scopedafterAllwould have been wrong here — closing at a describe's end takes the pool from later suites in the same file.$client.end(...)— left untouched; the pairing accepts either.database-pool-closing.test.ts): everycreateDatabasevariable inserver/tests/*.test.tsmust have a$client.close()or$client.end(somewhere in the same file.server/testsis outsidetsc, so this is the thing that notices file 118 reintroducing the leak.scripts/test-server-sharded.tsare replaced with what the issue measured: construction opens nothing, a pool costs itsmaxfrom its first query and is never reaped, exhaustion is a function of files run rather than imported, and an unclosed pool is a defect in the source rather than a harness ceiling. The sharded runner itself is unchanged and still worth having for wall-clock.Where it runs
Test infrastructure only; no server code is touched.
Boundary and audit
Changelog
server/testsandscripts/.Proof
No Bun or PostgreSQL on this machine (arm64 Linux CI box), so the local verification is tooling around the text, and the suite itself runs in CI:
server/tests: after the edit, zero offenders. Before it, the rule reported the 46 files this PR fixes (the issue counted 55 against an earlier tree; the same rule also finds the 14$client.endfiles already satisfied, and correctly ignores scoped pools that are closed in-scope).node --experimental-strip-types --checkon all 47 touched.tsfiles underserver/tests(the sharded runner script is not node-parseable even onmain— its edit is comment-only).$client.end(got nothing added on top of it; a scan for any variable carrying both aclose()and anend(finds none.afterAll(checked by hand: after the last delete, before the block's close), 43 as the body of a new trailing module-levelafterAll. No close was placed inside a describe-scoped hook; the first attempt did that to one file and was reverted and redone with a top-level-only rule.bun testitself (needs PostgreSQL); CI is the authoritative run, and the failure modes here are loud — a pool closed too early fails the deletes around it, a syntax error fails the file's import.