Skip to content

fix(deploy): four things that were already broken, found on the way to blue/green - #443

Merged
athvin merged 1 commit into
mainfrom
bm/bluegreen-p3-latent-bugs
Nov 3, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/bluegreen-p3-latent-bugs

Conversation

@athvin

@athvin athvin commented Nov 3, 2026

Copy link
Copy Markdown
Owner

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 deadlock

ensure_schema is 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:

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 — 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.

result
unserialised (before) 3 failures in 3 runs, always round 0
serialised (after) 4 passes in 4 runs

Why it matters: a deadlock victim's ensure_schema returns Err and main.rs exits 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 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. Since 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 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.

policy selector : {'app.kubernetes.io/name': 'web-api'}
policy ports    : [3000]
matching pods   : ['web-api']
er-api port     : [8000] -> in policy? False

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-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. So every suspend/resume cycle 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, not a write-back) 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 self-heals before picking a number. It doesn't — there's 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 actually in flight — an idle dispatcher exits within one poll.


Verification

  • make check green.
  • The race test run against a real Postgres and observed failing before the fix, in both directions, with the counts above. It is Postgres-gated, so it runs in the DuckLake-e2e legs rather than in make check.
  • helm template + kubeconform -strict clean on the default, kind and dev-namespace renders.

Side-finding, not fixed here

The DSN that both pg_schema_replay.rs and the Makefile print — user=er password=er dbname=er — doesn't match what frontend/dev/compose.yaml actually starts. It sets only POSTGRES_PASSWORD, so the role and database are both postgres. 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

…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]>
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.

2 participants