forge: remove Darling host-runtime smoke test (root cause) + keep PostgreSQL off /dev/shm (sysv) + pin CloudHSM permalinks #144
No reviewers
Labels
No labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
key-store/key.store!144
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/postgres-devshm-orphan-watchdog"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Root cause (found)
The 2026-08-18 21:40→04:57 UTC PostgreSQL outage — every new backend dying with
could not open shared memory segment "/PostgreSQL.<n>": No such file or directorywhile the postmaster stayed up — was caused bykey-store-darling-smoke.service. That timer ran the setuid Darling launcher in the host mount namespace every ~6h;darlingserverdoesunshare(CLONE_NEWNS)thenumount/mount /dev/shmbefore making/MS_SLAVE. On systemd'sMS_SHAREDroot the busyumounthitsEBUSYand a fresh empty tmpfs gets stacked onto the host/dev/shm, hiding PG's live segments./proc/1/mountinfoshowed 4 stacked/dev/shmlayers; onsets tracked the smoke timer to the second. (Credit: parallel wave-6 RCA.)It was a mount overlay, not a deletion — which is why the "deleter" left no journal entry, and why an unlink-audit was the wrong tool.
Fix (per direction: "remove all darling smoke testing" + "stop using /dev/shm")
key-store-darling-smoke.service+.timerandScripts/darling-bazel-smoke.sh. The rest of Darling (the Apple-build runner integration, agent image, setuid wrapper) is left intact./dev/shm—dynamic_shared_memory_type = "sysv"(+kernel.shmmni4096→32768 for SysV headroom).shared_memory_typeis alreadymmap, so PG then keeps no/dev/shmfiles and is immune to any future/dev/shmremount/wipe.5.18.0-1,3.4.4-1) instead of the mutable_latest_objects. AWS republished_latest_on 2026-08-19, which broke the fixed-output hashes and blocked every forge rebuild; versioned permalinks can't drift.Dropped from the earlier revision of this PR: the
postgresql-shm-watchdogand/dev/shmaudit layers — the audit was the wrong tool for a mount-stacking cause, and with the trigger removed + PG off/dev/shmthe recovery/diagnostic layers are moot (PG FATAL/backup alerting is owned by the wave-6 patch).Notes
/dev/shmlayers clear on the next reboot; do notumountthe top layer while PG runs on it.key-store-darling-smoke.timerwas manually stopped at 06:14Z; this makes the removal permanent so a switch/reboot can't re-arm it.Validation
nix-instantiate --parseclean on all three files.nixos-rebuild switch(restarts postgresql once for the sysv change; rebuilds the self-sourced container images, now buildable via the permalinks).On 2026-08-18 21:40:18 UTC the PostgreSQL DSM control segment /dev/shm/PostgreSQL.4007731292 was unlinked out from under the live postmaster (PID 269679 kept running the whole time). From that instant every NEW backend died with `could not open shared memory segment "/PostgreSQL. 4007731292": No such file or directory` + `can't attach the same segment more than once`, so Forgejo Actions, Authentik, PostHog, agent-dispatcher and the winrunner dispatch loop all failed for ~7h. Because the postmaster stayed up, systemd saw nothing wrong; service only returned after a manual `systemctl restart postgresql` at 04:57 UTC recreated the segment. Ruled out as the deleter: logind RemoveIPC (=no on this host), systemd-tmpfiles (no rule touches /dev/shm), a deploy/activation (none ran at 21:40), and an OOM/crash of the postmaster (it survived). The unlink correlates tightly with podman/authentik container-teardown churn (authentik-server had been crash- looping on a ~30s cycle for ~42h; its container died at 21:40:18.685, the same instant) but the exact unlink call left no journal entry and the container IPC mode is `shareable`, so the mechanism is not yet proven from logs. Three layers, all in nixos/keystore-forge.nix: 1. Prevention: services.postgresql.settings.dynamic_shared_memory_type = "sysv" moves DSM out of /dev/shm into kernel SysV IPC (still RAM-backed, protected by RemoveIPC=no). shared_memory_type is already mmap, so PostgreSQL then keeps NO files in /dev/shm and a /dev/shm wipe can no longer orphan it. kernel.shmmni raised 4096 -> 32768 for ample SysV segment headroom (~1 in use at rest; shmmax/shmall already effectively unbounded). 2. Recovery: postgresql-shm-watchdog.{service,timer} probes a fresh backend every 30s and, ONLY on the exact "could not open shared memory segment" signature, restarts postgresql (with a 5-min cooldown). Any other failure is left to normal systemd handling, so it cannot mask unrelated problems. Turns a silent multi-hour outage into a <=30s blip even if some other actor wipes /dev/shm in future. 3. Diagnostic: enable auditd + audit unlink/rename under /dev/shm by non-postgres uids (key dev_shm_delete). auditd/inotify-tools were both absent, so nothing could name the deleter; `ausearch -k dev_shm_delete` will capture pid/comm/exe on the next occurrence. Deploy is founder-gated (in-flight KSE-0182 OpenBao work on the forge). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>AWS republished cloudhsm-{cli,pkcs11}_latest_u24.04_amd64.deb on 2026-08-19 01:01-01:02 UTC (x-amz-version-id changed), so the pinned fixed-output hashes stopped matching. This broke every forge toplevel rebuild that touches the flake source (the CloudHSM SDK image is self-sourced) with: error: hash mismatch in fixed-output derivation '...cloudhsm-cli_latest...deb' Re-pinned to the current content. The u18.04 (SDK3/kmu) deb is unchanged. Added a note: these track AWS's mutable "latest" objects and will drift again; a versioned CloudHsmClient URL would be the durable fix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>Root cause of the 2026-08-18 21:40->04:57 PostgreSQL outage (wave-6 RCA, confirmed by the host mount table): key-store-darling-smoke.service ran the setuid Darling launcher in the HOST mount namespace every ~6h. darlingserver unshares CLONE_NEWNS then umount/mounts /dev/shm BEFORE making / MS_SLAVE; on systemd's MS_SHARED root the busy umount hits EBUSY and stacks a fresh empty tmpfs onto the host /dev/shm, hiding PostgreSQL's live segments so every NEW backend fails with `could not open shared memory segment ... No such file or directory` while the postmaster stays up (silent, systemd sees it healthy). /proc/1/mountinfo showed 4 stacked /dev/shm layers; onsets tracked the smoke timer to the second. Fix per founder direction ("remove all darling smoke testing" + "stop using /dev/shm"): - Remove key-store-darling-smoke.service + .timer (the recurring trigger) and Scripts/darling-bazel-smoke.sh. The rest of Darling (the Apple-build runner integration, agent image, setuid wrapper) is left intact. - Keep PostgreSQL off /dev/shm: dynamic_shared_memory_type=sysv (+ kernel.shmmni headroom). With shared_memory_type already mmap, PG keeps NO /dev/shm files and is immune to any future /dev/shm remount/wipe. - Drop the earlier postgresql-shm-watchdog and /dev/shm audit layers: the unlink-audit was the wrong tool for a mount-stacking cause, and with the trigger removed + PG off /dev/shm the recovery/diagnostic layers are moot (PG FATAL/backup alerting is owned by the wave-6 patch). The 4 stacked /dev/shm layers already present clear on the next reboot; do NOT umount the top layer while PG runs on it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>forge postgres: move DSM off /dev/shm (sysv) + orphaned-segment watchdog + /dev/shm auditto forge: remove Darling host-runtime smoke test (root cause) + keep PostgreSQL off /dev/shm (sysv) + pin CloudHSM permalinksandroid referenced this pull request2026-10-16 02:51:59 +00:00
android referenced this pull request2026-10-18 20:16:58 +00:00