Repository navigation
fix(deploy): four things that were already broken, found on the way to blue/green - #443
Merged
Merged
Conversation
…o blue/green
None of these are blue/green features. They are bugs the work surfaced, each
of which bites a deploy today, and each is independent of the others.
**1. `ensure_schema`'s phase 4 ran unserialised, and it really deadlocks.**
`ensure_schema` is six transactions, not one, releasing the advisory xact lock
between each. Five of them re-take it; the deferred-baseline replay did not —
the one phase executing catalog DDL with nothing stopping another process from
doing the same. Its own module doc says the lock exists because "the
drop-then-recreate index idiom deadlocks without serialization".
Observed, with six concurrent boots against an aged store:
ERROR: deadlock detected
DETAIL: Process A waits for ShareRowExclusiveLock on relation R; blocked by B.
Process B waits for ShareRowExclusiveLock on relation R; blocked by A.
A mutual lock UPGRADE, which is not the cycle phase 4's own comment suggests
("so the new-named locks exist before the old-named ones are dropped") — each
process already holds a weaker lock on the relation and both then need
ShareRowExclusiveLock, a level that comes from the trigger and foreign-key
statements in the deferred set rather than from the indexes.
**Two concurrent boots never show it**, which is why it survived: phases 1-3
all take the lock, so a pair serialises through them and is offset by the time
either reaches phase 4. The first version of this test used two and passed
against the unfixed code. Six overlap. Measured: 3 failures in 3 runs
unserialised, 4 passes in 4 runs serialised.
A deadlock victim's `ensure_schema` returns Err and `main.rs` exits non-zero,
so in the cluster this is an init container that fails and a pod that never
starts — and if the rolled-back transaction was the one creating
`jobs_one_active_per_dataset`, the queue comes up without its
one-active-job-per-dataset guarantee. Four processes do this concurrently in a
real deploy: the `er-migrate` init container, the API's boot, the standalone
dispatcher's boot, and a hand-run `er-server migrate`.
**2. `allow-alb-to-web` selected nothing.**
Its `podSelector` was `app.kubernetes.io/name: er-web`, from when the BFF was
its own Deployment. After the pods were merged the only pod carries
`name: web-api`, so the policy matched **no pod at all** and
`default-deny-ingress` would have blackholed the ALB the first time
`ingress.enabled` was flipped. Nothing caught it because both halves are off by
default and are meant to be enabled together — the failure was waiting at the
end of task 1.4, not in any diff.
Verified by rendering both charts and intersecting labels, including the part
that matters for §4.1: selecting the merged pod does NOT expose the control
plane, because the rule admits one port (3000) and er-server's 8000 is not in
it. A cross-chart assertion for this belongs in the chart-validation gate,
which has nothing to assert against today.
**3. `make dev-resume` left the dispatcher dead.**
`dev-suspend` scales `deployment --all --replicas=0`; resume named only
`web-api` — correct when the dispatcher ran in-process in that pod, wrong since
the §6.7 split. Every suspend/resume cycle therefore left `er-dispatcher` at
zero replicas permanently and the queue silently stopped draining, with nothing
in the web-api pod to say why. Resuming `--all` keeps the two in step by
construction rather than by a list someone has to remember to update.
**4. The dispatcher's SIGTERM drain had 30 seconds.**
`dispatcher_bin.rs` installs a drain — finish the in-flight job, exit at the
next loop top — and the chart gave it the Kubernetes default, which a legacy
in-process run (a whole DuckDB pipeline) blows through. The SIGKILL then
strands the job in `dispatching`/`running` holding the dataset's partial unique
index, blocking every later job for that dataset. I checked whether that is
self-healing before picking a number: it is not. There is no startup reclaim
for the legacy arm, and `pg::resume_job` is an OPERATOR action that 409s on
anything else, so recovery is a human.
300s, and deliberately NOT sized to the longest possible run: `Recreate` makes
the deploy wait for this pod to go, and the CI deploy's
`helm upgrade --wait --timeout 10m` would fail outright if the grace period
approached it. The coupling is now written down in both places, because the two
numbers have to move together. Paid only when a job is in flight — an idle
dispatcher exits within one poll.
Verified: `make check` green. The race test run explicitly against a real
Postgres and **observed failing before the fix**, in both directions, with the
counts above. `helm template` + `kubeconform -strict` clean on the default,
kind and dev-namespace renders.
Side-finding, not fixed here: the DSN `pg_schema_replay.rs` and the Makefile
both print (`user=er password=er dbname=er`) does not match what
`frontend/dev/compose.yaml` starts — it sets only `POSTGRES_PASSWORD`, so the
role and database are both `postgres`. The new test's header carries the
spelling that works.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Nov 3, 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.
None of these are blue/green features. They're bugs the work surfaced — each bites a deploy today, and each is independent of the others.
1.
ensure_schema's phase 4 ran unserialised, and it really does deadlockensure_schemais six transactions, not one, releasing the advisory xact lock between each. Five re-take it. The deferred-baseline replay did not — the one phase executing catalog DDL with nothing stopping another process doing the same. Its own module doc says the lock exists because "the drop-then-recreate index idiom deadlocks without serialization."Observed, six concurrent boots against an aged store:
A mutual lock upgrade — not the cycle phase 4's own comment suggests. Each process already holds a weaker lock on the relation and both then need
ShareRowExclusiveLock, a level that comes from the trigger and foreign-key statements in the deferred set, not from the indexes.Two concurrent boots never show it, and that's why it survived. Phases 1–3 all take the lock, so a pair serialises through them and is offset by the time either reaches phase 4. My first version of this test used two boots and passed against the unfixed code. Six overlap.
Why it matters: a deadlock victim's
ensure_schemareturnsErrandmain.rsexits non-zero — in the cluster, an init container that fails and a pod that never starts. And if the rolled-back transaction was the one creatingjobs_one_active_per_dataset, the queue comes up without its one-active-job-per-dataset guarantee. Four processes do this concurrently in a real deploy: theer-migrateinit container, the API's boot, the standalone dispatcher's boot, and a hand-runer-server migrate.2.
allow-alb-to-webselected nothingIts
podSelectorwasapp.kubernetes.io/name: er-web, from when the BFF was its own Deployment. Since the pods were merged the only pod carriesname: web-api, so the policy matched no pod at all — anddefault-deny-ingresswould have blackholed the ALB the first timeingress.enabledwas flipped on.Nothing caught it because both halves are off by default and are meant to be enabled together. The failure was sitting at the end of task 1.4, not in any diff.
Verified by rendering both charts and intersecting labels, including the part that matters for §4.1: selecting the merged pod does not expose the control plane, because the rule admits one port (3000) and er-server's 8000 isn't in it.
A cross-chart assertion for this belongs in the chart-validation gate — which has nothing to assert against today, and is the next PR in this stack.
3.
make dev-resumeleft the dispatcher deaddev-suspendscalesdeployment --all --replicas=0; resume named onlyweb-api— correct when the dispatcher ran in-process in that pod, wrong since the §6.7 split. So every suspend/resume cycle lefter-dispatcherat zero replicas permanently and the queue silently stopped draining, with nothing in the web-api pod to say why.Resuming
--allkeeps the two in step by construction, rather than by a list someone has to remember to update.4. The dispatcher's SIGTERM drain had 30 seconds
dispatcher_bin.rsinstalls a drain — finish the in-flight job, exit at the next loop top — and the chart gave it the Kubernetes default, which a legacy in-process run (a whole DuckDB pipeline, not a write-back) blows through. The SIGKILL then strands the job indispatching/runningholding the dataset's partial unique index, blocking every later job for that dataset.I checked whether that self-heals before picking a number. It doesn't — there's no startup reclaim for the legacy arm, and
pg::resume_jobis an operator action that 409s on anything else, so recovery is a human.300s, and deliberately not sized to the longest possible run:
Recreatemakes the deploy wait for this pod to go, and the CI deploy'shelm upgrade --wait --timeout 10mwould fail outright if the grace period approached it. The coupling is now written down in both places because the two numbers have to move together. Paid only when a job is actually in flight — an idle dispatcher exits within one poll.Verification
make checkgreen.make check.helm template+kubeconform -strictclean on the default, kind and dev-namespace renders.Side-finding, not fixed here
The DSN that both
pg_schema_replay.rsand theMakefileprint —user=er password=er dbname=er— doesn't match whatfrontend/dev/compose.yamlactually starts. It sets onlyPOSTGRES_PASSWORD, so the role and database are bothpostgres. That cost me a run; the new test's header carries the spelling that works. Left alone because fixing it properly means deciding which one is meant to be true.🤖 Generated with Claude Code