Skip to content

test/docker: bake mysql+postgres data dirs so cold start is ~2-3s, stop healthcheck wedge - #33822

Merged
Jarred-Sumner merged 8 commits into
mainfrom
farm/cd02395e/mysql-healthcheck-wedge
Jul 10, 2026
Merged

Jarred-Sumner merged 8 commits into
mainfrom
farm/cd02395e/mysql-healthcheck-wedge

Conversation

@robobun

@robobun robobun commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator

What

Fixes the recurring application not healthy after 1m0s flake that takes out every mysql-backed test file on alpine shards (26030, 24850, 26063, 28632, sql-mysql.*, integration/mysql2), by baking pre-initialized data directories into the mysql and postgres test images so cold container start is ~2-3s instead of ~60s, and by removing the healthcheck configuration that turned a slow start into a permanent wedge.

  • Dockerfile.mysql-plain, Dockerfile.mysql-native-password, and the mysql-tls Dockerfile run the stock entrypoint once at docker build time with MYSQL_INITDB_SKIP_TZINFO=1 against a sibling datadir (the base image's VOLUME /var/lib/mysql discards build-time writes there). At container start the entrypoint sees the datadir is populated and execs mysqld directly.
  • Dockerfile.postgres-plain, Dockerfile.postgres-auth, and the postgres-tls Dockerfile do the same against a PGDATA outside VOLUME /var/lib/postgresql/data.
  • Every healthcheck's interval drops from 1h to 5s.
  • compose up --wait-timeout goes from 60 to 180 and the container beforeAll hook timeouts go to 240s.
  • scripts/bootstrap.sh bumped to v38 so the next Linux AMI bake runs prepare-ci.ts against the new compose file and pre-builds bun-mysql-*:local / bun-postgres-*:local into the runner. Until the v38 AMIs are published each shard still pays one image build under parallel prestart; afterwards it is just docker run (~2-3s).

Why

The ~62s mysql cold start breaks down as: ~39s loading /usr/share/zoneinfo into mysql.time_zone_* via mysql_tzinfo_to_sql, ~15s mysqld --initialize-insecure, and ~8s of entrypoint setup plus the temp-server bounce. No test touches MySQL's named-timezone tables (the datetime-roundtrip test only varies the process TZ, not the MySQL session time_zone), so the tzinfo load is dead weight, and the rest is deterministic and can run at image-build time instead of every container start. Postgres's own init (initdb + temp server + init scripts) is ~5-8s, but on alpine shards it queued behind the three parallel mysql builds and was observed at 130-220s ensure-to-ready.

On alpine 3.23 CI hosts, mysql's ~62s overshot start_period: 60s, and once start_period elapses Docker's health monitor switches from start_interval: 1s to interval: 1h. So the container sat at health: starting for an hour even though mysqld was accepting TCP connections two seconds later, and every compose up --wait --wait-timeout 60 timed out from then on. Each affected test file was retried four times at 60s apiece.

From build 70876's alpine x64-baseline shard:

mysql_plain-1  | 2026-07-09 06:38:49 [Entrypoint]: Entrypoint script ... started.
...
mysql_plain-1  | 2026-07-09T06:39:51 [MY-010931] ... ready for connections. ... port: 3306

62s from entrypoint to ready, yet docker compose ps two minutes later still shows:

bun-test-services-mysql_plain-1 ... Up 2 minutes (health: starting)

because the next probe is scheduled for ~07:39.

Sampling the last 30 failed :alpine: 3.23 test-bun jobs, 20 were this exact error (x64, x64-baseline, aarch64). 0 of 20 sampled debian/ubuntu failures were.

tmpfs is dropped for both: the baked data dir lives on the container's CoW layer, so a fresh container is still a fresh database/cluster and the light test workloads don't need RAM-backed I/O. interval: 5s everywhere means that even if some future service overshoots its start_period, it recovers within one probe instead of freezing compose up --wait for an hour; a SELECT 1 / pg_isready every 5s is negligible and would need 30 consecutive failures (150s) to mark a running container unhealthy.

Verification

  • build 70904 (mysql pre-bake, old AMIs): all 60 alpine shards pass; a solo mysql_plain compose build + up --wait on alpine completes in ~15s, debian completes all three in parallel in ~91s.
  • This commit carries [build linux images] so CI bakes throwaway v38 AMIs with the new images pre-built and runs the suite on them. Once green the subject can be switched to [publish images] per the bootstrap header.

On alpine CI hosts, mysql:8.4 first-boot init (timezone load + temp
server restart) regularly takes 62-65s when three mysqld containers are
starting in parallel. That overshoots start_period: 60s, at which point
the engine switches the probe cadence from start_interval: 1s to
interval: 1h, so the container sits at 'health: starting' for an hour
even though mysqld is accepting connections two seconds later. Every
subsequent compose up --wait --wait-timeout 60 then times out, and each
mysql-backed test file burns 60s per retry before failing.

In a sample of the 30 most recent failed alpine test-bun jobs, 20 were
this exact 'application not healthy after 1m0s' error (x64, x64-baseline
and aarch64); 0 of 20 debian/ubuntu failures were.

Drop interval to 5s on every service that had it at 1h, so overshooting
start_period is a one-probe delay rather than an hour-long wedge. Raise
the mysql services' start_period to 180s, the up --wait-timeout to 180,
and the container beforeAll hook timeouts to 240s to match.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6d18b9a1-0e32-4210-a22e-6eda7e76d6a0

📥 Commits

Reviewing files that changed from the base of the PR and between 2e3c961 and b6e37ee.

📒 Files selected for processing (7)
  • scripts/bootstrap.sh
  • test/docker/Dockerfile.mysql-plain
  • test/docker/Dockerfile.postgres-auth
  • test/docker/Dockerfile.postgres-plain
  • test/docker/README.md
  • test/docker/docker-compose.yml
  • test/js/sql/docker-tls/Dockerfile

Walkthrough

This PR adds two new MySQL Docker test images (plain and native-password) with pre-initialized datadirs, updates the mysql-tls Dockerfile similarly, rewires docker-compose.yml to build these local images and reduces healthcheck intervals from 1h to 5s, and increases various wait-timeout and beforeAll timeout values (60s→180s, 120_000→240_000ms) across compose helpers and dependent tests.

Changes

MySQL Test Container and Docker Compose Timing Changes

Layer / File(s) Summary
New MySQL plain and native-password Dockerfiles
test/docker/Dockerfile.mysql-plain, test/docker/Dockerfile.mysql-native-password
Two new Dockerfiles build MySQL images with pre-initialized datadirs, polling SELECT 1 during build before shutdown, and set runtime CMD to reuse the baked-in datadir.
mysql-tls Dockerfile datadir pre-initialization
test/js/sql/mysql-tls/Dockerfile
Adds a build-time init step (start mysqld, poll readiness, shutdown) and an explicit runtime CMD using the pre-initialized datadir.
docker-compose service wiring and healthcheck intervals
test/docker/docker-compose.yml, test/docker/README.md
Switches mysql_plain/mysql_native_password services to build from the new local Dockerfiles, reduces healthcheck interval from 1h to 5s across multiple services, and updates README's file tree/script name.
Compose wait-timeout increase
test/docker/index.ts
Increases docker compose up --wait-timeout from 60s to 180s with an updated comment.
Dependent test beforeAll timeout doubling
test/harness.ts, test/js/valkey/test-utils.ts, test/js/valkey/valkey.test.ts, test/js/web/websocket/autobahn.test.ts, test/js/web/websocket/websocket-proxy.test.ts
Doubles beforeAll timeouts from 120_000 to 240_000 ms and updates comments to reflect the new 180s compose wait-timeout bound.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly reflects the main change: pre-baking database images to speed cold starts and avoid healthcheck wedging.
Description check ✅ Passed The description covers the PR purpose and verification, but it doesn't match the repository's required section headings exactly.

Comment @coderabbitai help to get the list of available commands.

@robobun

robobun commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 8:07 PM PT - Jul 9th, 2026

❌ @robobun, your commit b6e37ee has 3 failures in Build #71237 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 33822

That installs a local version of the PR into your bun-33822 executable, so you can run:

bun-33822 --bun

@github-actions github-actions Bot added the claude label Jul 9, 2026
~39s of the ~62s mysql first-boot init is mysql_tzinfo_to_sql loading
/usr/share/zoneinfo into mysql.time_zone_*; ~15s is mysqld
--initialize-insecure; the rest is the entrypoint's temp-server bounce.
No bun test uses MySQL's named-timezone tables (the datetime-roundtrip
test only varies the process TZ, not the session time_zone).

Move all of that to docker build time: new Dockerfile.mysql-plain and
Dockerfile.mysql-native-password (and the existing mysql-tls Dockerfile)
run the stock entrypoint once with MYSQL_INITDB_SKIP_TZINFO=1 against a
sibling datadir (the base image's VOLUME /var/lib/mysql discards
build-time writes there), wait for TCP ready, shut down, and set CMD to
point mysqld at the baked dir. At container start the entrypoint sees
the datadir is populated and execs mysqld directly.

tmpfs is dropped since the baked dir lives on the container's CoW layer;
a fresh container is still a fresh database.
@robobun robobun changed the title test/docker: stop mysql healthcheck wedging at 'starting' on slow init test/docker: bake mysql data dirs so cold start is ~3s, stop healthcheck wedge Jul 9, 2026
Comment thread test/docker/index.ts Resolved
Comment thread test/docker/Dockerfile.mysql-plain Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier nits are addressed and I found nothing further, but this reworks how the mysql test containers are built (baked datadir, dropped tmpfs) and the author notes it couldn't be verified locally — worth a human confirming the alpine lanes in #70904 are green before merging.

Extended reasoning...

Overview

Test-infrastructure-only change addressing a recurring alpine CI flake. Adds two new Dockerfiles (Dockerfile.mysql-plain, Dockerfile.mysql-native-password) and reworks test/js/sql/mysql-tls/Dockerfile to run the stock mysql entrypoint at docker build time, baking a pre-initialized datadir into the image at /var/lib/mysql-init (sidestepping the base image's VOLUME /var/lib/mysql). Drops tmpfs and environment: from the mysql compose services (env now baked via ENV), changes every healthcheck interval from 1h to 5s, raises compose up --wait-timeout 60→180, and bumps five beforeAll hook timeouts 120s→240s to match. README architecture tree updated. No src/ code touched.

Security risks

None. Changes are confined to local test-container Dockerfiles, compose config, and test hook timeouts. No auth, crypto, or user-facing surface.

Level of scrutiny

Medium. It's test-only, but it's a substantive redesign of how three CI test containers are provisioned, using a somewhat non-obvious technique (build-time entrypoint run + alternate datadir to dodge VOLUME). If the baked image is wrong it takes out every mysql-backed test file. The PR description explicitly states Docker pulls were blocked in the authoring environment, so the new images were not built or run locally — correctness rests entirely on this PR's CI build (#70904).

Other factors

I left two nit-level comments on earlier revisions (missed sibling timeout in websocket-proxy.test.ts; README file-tree drift) — both were fixed in follow-up commits and are reflected in the current diff. The bug-hunting pass found nothing. The interval: 1h→5s and timeout bumps are mechanically sound. The removal of tmpfs is justified (fresh container → fresh CoW layer → fresh DB), but it plus the datadir relocation is the kind of infra decision a maintainer should glance at, and the pending alpine CI result is the actual verification. Deferring rather than approving so a human confirms the alpine lanes pass.

robobun added 2 commits July 9, 2026 09:11
With three mysql images building in parallel (coordinator prestart starts
mysql_plain, mysql_native_password and mysql_tls together), each RUN's
mysqld --initialize contends for the host and on alpine CI runs past the
previous 60-iteration poll, failing the prestart build. debian hosts
finish the same parallel build in ~30s; the subsequent solo retry on
alpine finishes in ~15s, so the approach is sound, only the bound was
tight. 180 matches the compose up --wait-timeout.
…o runner AMIs

prepare-ci.ts (run at AMI bake time) picks up the new Dockerfile.mysql-*
build sections, so bun-mysql-plain/native-password/tls:local are
pre-built in the runner and per-shard mysql container start is ~3s
instead of paying the image build.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/docker/Dockerfile.mysql-native-password`:
- Around line 5-8: The baked MySQL credentials in the
Dockerfile.mysql-native-password setup are being fixed at image build time, so
runtime env-var overrides will be ignored once the datadir is initialized.
Update the MySQL initialization flow in this Dockerfile so the root password and
related credentials are applied at container startup instead of hardcoded via
ENV during build, following the same approach used to avoid freezing credentials
in Dockerfile.mysql-plain.

In `@test/docker/Dockerfile.mysql-plain`:
- Around line 14-22: The mysqld init/poll/shutdown sequence in this Dockerfile
is duplicated across multiple Dockerfiles, so extract it into a shared helper
script such as bake-mysql.sh and invoke it from Dockerfile.mysql-plain,
Dockerfile.mysql-native-password, and the mysql-tls Dockerfile. Keep the shared
logic in one place, parameterize only the credentials/flags each image needs,
and replace the inline RUN block with a call to the script so the polling and
shutdown behavior stays consistent everywhere.
- Around line 14-24: The MySQL image build step in Dockerfile.mysql-plain bakes
initialization data into /var/lib/mysql-init, so runtime MYSQL_ROOT_PASSWORD,
MYSQL_ALLOW_EMPTY_PASSWORD, and MYSQL_DATABASE overrides will be ignored by
docker-entrypoint.sh. Add a clear comment near the RUN/CMD setup explaining that
this is an intentional fixed test fixture and that the init directory prevents
runtime env-based reconfiguration. Use the existing docker-entrypoint.sh mysqld
bootstrap block and CMD ["mysqld", "--datadir=/var/lib/mysql-init"] as the
anchor points.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 286ec15e-361d-417a-bd6b-67545a41c91f

📥 Commits

Reviewing files that changed from the base of the PR and between bdd6c1f and 2e3c961.

📒 Files selected for processing (11)
  • test/docker/Dockerfile.mysql-native-password
  • test/docker/Dockerfile.mysql-plain
  • test/docker/README.md
  • test/docker/docker-compose.yml
  • test/docker/index.ts
  • test/harness.ts
  • test/js/sql/mysql-tls/Dockerfile
  • test/js/valkey/test-utils.ts
  • test/js/valkey/valkey.test.ts
  • test/js/web/websocket/autobahn.test.ts
  • test/js/web/websocket/websocket-proxy.test.ts

Comment thread test/docker/Dockerfile.mysql-plain Resolved
Comment thread test/docker/Dockerfile.mysql-plain Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier nits are addressed and I found nothing further, but since this reworks the mysql CI container images and triggers an AMI rebake (with a manual [publish images] follow-up), it's worth a quick human sign-off from whoever owns the image-bake workflow.

Extended reasoning...

Overview

This PR is entirely test/CI infrastructure — no src/ runtime code is touched. It adds three baked-data-dir mysql Dockerfiles (Dockerfile.mysql-plain, Dockerfile.mysql-native-password, and the updated mysql-tls/Dockerfile), rewires docker-compose.yml to build them locally instead of using stock mysql:8.x images, drops every healthcheck interval from 1h to 5s, raises compose up --wait-timeout from 60→180 in test/docker/index.ts, bumps five beforeAll hook timeouts from 120s→240s to match, updates the test-docker README, and bumps scripts/bootstrap.sh to v38 so the next Linux AMI bake pre-builds the new images. The commit subject carries [build linux images] to bake throwaway AMIs for verification.

Security risks

None. This is test-container orchestration and CI image provisioning; no auth, crypto, permissions, or user-facing code paths are involved. The Dockerfiles use fixed test credentials (bun/empty) that were already in docker-compose.yml before this change.

Level of scrutiny

Medium. Nothing here ships in the Bun binary, and the worst-case failure mode is CI going red (immediately visible, trivially revertible). However, it does change how every mysql-backed test file gets its container across all Linux shards, removes tmpfs mounts (relying on CoW-layer freshness instead), and triggers the AMI-bake workflow — which per the bootstrap.sh header and PR description has a manual [build linux images] → [publish images] transition that someone needs to own once CI is green.

Other factors

Both nits I raised earlier (the missed websocket-proxy.test.ts timeout sibling and the README file-tree drift) were fixed in 0d3b798 and d25a0a1. Two further commits landed after: 2e3c961 added the bounded 180s readiness poll to the Dockerfile RUN step (a good defensive addition — the post-loop mysql ... -e 'SELECT 1' without redirection means a poll timeout fails the build rather than baking a bad image), and 3bfb1e7 added the bootstrap v38 bump. The PR description cites build 70904 with all 60 alpine shards passing on the pre-bake path. The design rationale (VOLUME discards build-time writes → use /var/lib/mysql-init; interval: 1h wedges --wait after start_period overshoot → use 5s) is sound and well-documented in comments. I'm deferring rather than approving primarily because the AMI rebake/publish workflow is an operational decision with a documented manual follow-up step, not because of any code concern.

…tgres services

Same treatment as the mysql images: run the stock entrypoint once at
docker build time against a PGDATA outside the base image's
VOLUME /var/lib/postgresql/data, so cold container start is
'exec postgres' (~1-2s) instead of initdb + temp server + init scripts.

On shards that prestart postgres alongside the three mysql builds,
postgres_plain was taking 130-220s on alpine (28-57s on debian) because
its compose build queued behind the parallel mysql image builds; with
both sets pre-built in the AMI, none of that contention exists.

Also drops the postgres tmpfs mounts and environment: blocks (now baked
via ENV), and notes in the mysql-plain comment that the init-time
MYSQL_* env vars are build inputs only.
@robobun robobun changed the title test/docker: bake mysql data dirs so cold start is ~3s, stop healthcheck wedge test/docker: bake mysql+postgres data dirs so cold start is ~2-3s, stop healthcheck wedge Jul 9, 2026
@robobun

robobun commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

[build linux images] run 70954 finished: 292 passed, 2 unrelated failures (darwin webview.test.ts, debian x64-asan bun_http::http_thread SIGABRT; neither touches docker test infra).

On the throwaway v38 AMIs:

lane prestart (5 parallel services) before
debian/ubuntu 33-40s 91-99s
alpine 130-144s ~164s plus 4×60s retry burn

No build failures, no application not healthy wedges, all mysql/postgres-backed tests pass.

The remaining ~130s floor on alpine is pre-existing docker-daemon overhead, not the bake: a bare docker ps takes ~7.6s on the alpine runners vs ~2.1s on debian, and minio/redis_unified (unchanged by this PR) sit at the same ~130-144s there. Worth a separate look, but orthogonal to this change.

Ready for the [publish images] step per the bootstrap.sh header.

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

@robobun push a commit to this branch with [publish images] so we publish before merging

…to runner AMIs

[build linux images] run 70954 is green on the throwaway v38 AMIs (292
passed; the two failures are darwin webview.test.ts and a debian x64-asan
bun_http::http_thread SIGABRT, neither related to docker test infra).
Publish the real -v38 tag.
@robobun

robobun commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed b6e37ee with [publish images] to bake the real -v38 AMI tag.

@robobun

robobun commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

[publish images] run 71237 finished: all 8 build-image jobs passed (the real -v38 AMIs are published), 293 test jobs passed. The one red is a :darwin: 14 x64 shard that timed out, which this PR's Linux docker test-infra changes don't touch. Ready to merge.

@Jarred-Sumner
Jarred-Sumner merged commit 90f8746 into main Jul 10, 2026
83 of 85 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the farm/cd02395e/mysql-healthcheck-wedge branch July 10, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants