Files
ersatztv/scripts
timothy e8ad79623f fix(445): make the boot wait interruptible so a mid-boot signal can't orphan the server
Codex round-2 verdict was BLOCKED @ 2a5f26c0 on one High finding, which was
correct and is the subtlest defect in this whole change.

## The defect

Bash DEFERS a trapped signal while it waits on a FOREGROUND command. The boot was

    OUT="$(ETV_UI_PORT=... scripts/e2e-local.sh "$CONFIG_DIR")"

so a TERM arriving during the (up to 120s) readiness wait did not run `on_signal`
until boot completed — and a supervisor escalating TERM->KILL means the trap
never runs at all, orphaning the server on its port. The pidfile added in the
previous commit only helps IF the trap runs; this is the case where it doesn't.

Proved the mechanism in isolation rather than asserting it, since the real boot
is only ~2s locally and kept winning the race:

    foreground command substitution : TERM at t=1s -> trap ran at t=6s (deferred)
    background job + `wait`         : TERM at t=1s -> trap ran at t=1s (prompt)

## The fix

Boot in the background and `wait` on it. `wait` is interruptible, so the handler
runs immediately; by then e2e-local.sh has already written $ETV_PIDFILE, so
cleanup can reap a server whose PID this script has not yet parsed. Cleanup also
now stops the backgrounded e2e-local.sh itself, so it cannot sit waiting on a
server we just killed, and removes its temp output file.

Boot diagnostics are preserved on the failure path (verified with a deliberately
bad ETV_BUILD_CONFIG: the underlying "bin/<config> does not exist" error is
surfaced, along with the exit status, which is now propagated rather than
flattened to 1).

## Verification
- mechanism: deferred-vs-prompt trap proven as above
- passing run 3/3 green; failing run (--grep ZZZ_NOPE) exits 1
- boot-failure path prints e2e-local.sh's real error and its exit status
- targeted SIGTERM: exit 143, no listener, no stray process
- curl harness unaffected: 45/45 PASS
- no orphaned processes after the full gate (an earlier count of 1 was a
  graceful shutdown still in flight, not a leak — re-checked clean)

Refs #445
2026-07-25 14:04:52 +02:00
..
2024-01-15 10:29:07 -06:00
2024-01-16 13:28:46 -06:00