-
Notifications
You must be signed in to change notification settings - Fork 4.7k
test(sql): bound spawned fixture lifetime so a test timeout cannot leave orphans #32207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Unlike the other 8 spawns in this PR (short-lived bun fixture clients),
mysqld_safeis the long-running MariaDB server daemon — it is supposed to stay alive for the duration of the test, and.unref()does not cancel the spawn timeout timer. WithwaitForSocketbudgeted up to 30s for cold start, plusprovisionTcpUserand a debug/ASAN fixture run, the 60s timer can fire mid-test and SIGTERM the database out from under the fixture, causing a spurious failure. The PR's rationale (fixture clients hanging on pool drain) doesn't apply to the database daemon itself; suggest dropping this hunk or using a much larger bound (e.g. 300_000+).Extended reasoning...
What the bug is
This PR adds
timeout: 60_000to nineBun.spawncalls. Eight of them spawn short-lived bun fixture subprocesses that connect to a database, run a query, and exit — exactly the case the PR description targets. But the ninth, attest/js/sql/sql-mysql-column-name-digits.test.ts:91, spawnsmysqld_safe— the MariaDB server daemon itself. That process is intended to outlive the test body: it is.unref()'d, its stdio is ignored, andensureServerStarted()early-returns if the socket already exists from a prior run. Putting a 60s hard kill on it means the database server can be terminated while the test is still using it.Why
.unref()doesn't helpI verified in
src/runtime/api/bun/subprocess.zigthatjsUnref()only callsprocess.disableKeepingEventLoopAlive()and unrefs stdin/stdout/stderr — it does not touchevent_loop_timer. MeanwhilecomputeHasPendingActivity()returnstruewhile!process.hasExited(), which keeps the JS wrapper Strong-referenced, so GC will not collect the Subprocess and cancel the timer viafinalize()either. Therefore, 60 seconds afterensureServerStarted()runs,timeoutCallback()unconditionally callstryKill(killSignal)on the still-runningmysqld_safeprocess — regardless of.unref().Step-by-step trigger
isDockerEnabled() === false).beforeAll→ensureServerStarted()spawnsmysqld_safeat T=0 withtimeout: 60_000and calls.unref().waitForSocket(30_000)polls every 250ms. On a cold container start, MariaDB initialization can take a substantial fraction of that 30s budget — say T≈25s when the socket appears.provisionTcpUser()opens a root socket connection and runs 6 sequential SQL statements — a few more seconds.runFixture(url), which spawns a debug/ASAN bun subprocess (the file's other hunk), connects over TCP, and runs the query. Debug+ASAN bun startup alone is routinely 10–20s.mysqld_safe. MariaDB shuts down.CONNECTED; the test throwscould not connect to mysql://bun_sql_test@127.0.0.1:3306/...— a spurious failure unrelated to the column-name-digits regression under test.Why the PR rationale doesn't apply here
The PR description says: "the sql fixture subprocesses connect to a database and await the pool draining; under a regression that hangs the pool, the fixture never exits".
mysqld_safeis not a bun SQL fixture, has no JS pool to drain, and is not subject to a #32145-style hang. The timeout also doesn't achieve the orphan-prevention goal for this spawn: because the process is.unref()'d and never awaited, when the test-runner process exits the timer dies with it andmysqld_safeis orphaned regardless. So this hunk adds a flake risk without providing the intended safety.Fix
Either drop this one hunk (the
mysqld_safespawn), or use a bound comfortably larger than the worst-case test duration — e.g.timeout: 300_000or more — so the daemon is reaped only when the wholetest/js/sql/run is clearly stuck, not while a single slow cold-start test is still in flight.