Skip to content

ci(docker): cluster failover test on the candidate image (#290) - #322

Merged
Madraka merged 2 commits into
mainfrom
claude/selfhost-failover-290
Nov 29, 2026
Merged

Madraka merged 2 commits into
mainfrom
claude/selfhost-failover-290

Conversation

@Madraka

@Madraka Madraka commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

The cluster failover test the owner asked for on 2026-11-23 (RFC-0047 §7, §12). 0.11.0 shipped without one.

What it does

scripts/failover-smoke.ts is a new step, Cluster failover test, in docker.yml's build job. It runs after the Helm smoke on cloudhal:ci, the single-platform local copy (#312), so it gates tag like the other smokes.

  1. Start. Three instances run on compose.yml's SeaweedFS, all with the same config and one public origin. Instance a starts first: it runs the migrations and creates the site, so it owns the database and the scheduler objects. Then b and c join.
  2. Publish and schedule. The owner signs up and publishes. The starter post is retitled in a draft and put in a release due about 80 s later. The test checks that the change waits for its release.
  3. SIGKILL. a gets docker kill --signal KILL 10 s before the release is due. Within 60 s, b and c must both serve:
    • the home page and the post;
    • Studio's /api/admin/sites, which reads D1.
  4. Exactly once. The release, due during the outage, must reach published. It must have exactly one succeeded run, which did not start before its time, and the new title must be live on b and c. Then a starts again on its volume, rejoins and serves the change.
  5. SIGTERM. b and then c get docker stop --timeout 15 while the other two take a steady load (site, post and D1 read, every 100 ms, from 3 s before the stop to 25 s after). Not one request may fail. Each instance must exit by itself, without exit code 137, in under 15 s. One of b or c owns the database after step 3, so one of these stops is a real handoff.
  6. Final checks. No instance logged migration " (Self-host cluster: instances starting together race on migrations ("duplicate column name", uncaught) #309), and the release still has exactly one run.

What the first run found, and the fix

Run 46234540828 passed every step up to the second graceful stop. While c, which owned D1 after a's SIGKILL, stopped gracefully, one request to a got a 503 (site / at 191.3 s).

a's log at that moment:

cloudhal: the store could not be read before rendering Error: D1_ERROR: Network connection lost.
    at D1Driver.get … at SiteResolver.resolve

That 503 is RFC-0043's unavailable page. status-entry.ts answers it whenever the state read throws. The cause is a request that was on its way to the D1 object as the object moved to its new owner. This is a product bug, not a probe bug: the probe targets only a and b, which kept running, and every other request in those 28 s succeeded.

The fix, in @cloudhal/storage (patch changeset):

  • D1Driver retries get and all of a read-only statement (SELECT, or WITH without a write, never RETURNING), about 2 s in all.
  • It retries only on a lost connection or a Durable Object reset. It never retries overload or other errors.
  • It never retries writes or batches, because a lost write may have been applied.
  • This follows Cloudflare's guidance to retry idempotent statements, and it helps on Cloudflare too, where objects move after a deploy or an eviction.
  • test/d1-retry.test.ts covers it. test/d1.test.ts (the Miniflare D1 conformance suite) still passes.

Probe changes:

  • A failed answer now records its status, retry-after, the x-cloudhal-* headers and the start of its body.
  • The diagnostics print 300 log lines.

Docs: the guide's "Stopping" bullet now says reads are retried on the new owner, and that a write caught in the move fails once.

Bounds and diagnostics

  • Every docker call has a timeout, and every request has a 10 s AbortSignal.timeout. Each wait has its own deadline, and the step has timeout-minutes: 20.
  • Only 127.0.0.1 is used (CI: Docker image 'Build edge' hangs in the Swarm smoke test since 2026-11-23 (90-min timeout every run) #306).
  • On failure the test prints docker ps, each instance's health, site status, release, runs and /api/admin/schedules/status, and the last 150 log lines of every container.
  • The script exits 2 outside GitHub Actions (GITHUB_ACTIONS=true), so it never runs on a developer machine.

Docs

The self-host guide's "Several instances" section links the test and says what it checks. deploy/docker/README.md names it. The Limits section is unchanged, because none of its items is about failover.

@cloudhal/storage gets a patch changeset for the D1 read retry.

Checked locally

  • actionlint, pnpm lint, biome check --diagnostic-level=error, pnpm size:check
  • tsc on the script

There were no Docker runs locally: the PR's own docker.yml run is the test.

Closes #290

🤖 Generated with Claude Code

Madraka and others added 2 commits November 29, 2026 09:40
Three instances on SeaweedFS. The first is killed with SIGKILL ten seconds
before a scheduled release is due: the other two must serve the site and
Studio again within 60 s with the published content intact, and the release
must run exactly once, not early, and be live everywhere. The killed instance
rejoins on its volume; then b and c stop gracefully in turn while the others
take a steady load, with not one failed request and an exit within the grace
period. No instance may log a migration error.

Every docker command and request is bounded, the step has timeout-minutes,
and a failure prints each instance's state, release, runs, scheduler status
and log. The script refuses to run outside GitHub Actions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
…#290)

The failover test's first run found it: while c, the database's owner,
stopped gracefully, a's site Worker got "D1_ERROR: Network connection
lost" on its state read and answered RFC-0043's unavailable page (503)
once. A request on its way to a Durable Object that moves is lost; the next
one reaches the new owner, and Cloudflare's guidance is to retry such
errors when the statement is idempotent.

D1Driver now retries get and all of a read-only statement (SELECT, or WITH
without a write, never RETURNING) on a lost connection or an object reset,
about 2 s in all; overload, other errors, writes and batches fail as before.

The failover test now records a failed answer's status, retry-after and
x-cloudhal-* headers and the start of its body, and prints 300 log lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
@Madraka
Madraka merged commit efb0c89 into main Nov 29, 2026
12 checks passed
@Madraka
Madraka deleted the claude/selfhost-failover-290 branch November 29, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Self-host: a cluster failover test in CI (kill an instance, the others take over)

1 participant