Repository navigation
chore(deps): bump embedded-postgres to 18.6.0-beta.19 - #1429
Conversation
|
Code review (GPT 6.1 Sol, xhigh), four rounds, ending at Held from round one: the exit-hook patch is needed (as published, Found and fixed:
One nit, partly fixed: the PR body said the cleanup "waits until the group is empty", and it waits a bounded time; the body now says so. The helper's doc comment in Known and unchanged from main: SIGHUP to the dev supervisor stops Postgres and leaves the dev server running; a Postgres frozen for good during start-up is left behind. Not verified by anyone: SIGBREAK on Windows, and this cleanup on macOS (CI runs the file on Ubuntu only). |
e51dca1 to
11d063e
Compare
embedded-postgres 18.6 ships Postgres 18.6 and moves its shutdown hook from async-exit-hook, which we patched, to exit-hook 5. exit-hook keeps a failed run's exit code without help, so the async-exit-hook patch goes. It differs elsewhere: on process.exit() it prints a termination notice and never starts the hook, so a running cluster is left behind, and it no longer stops Postgres on SIGHUP or SIGBREAK. A small patch to exit-hook restores what async-exit-hook did on those paths, and the embedded Postgres shutdown test now covers both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
exit-hook forces a process out five seconds after SIGINT or SIGTERM, the same five seconds the supervisor gives its server before SIGKILL, so the hook could end the supervisor with the server still running. The supervisor now loads embedded-postgres as it starts the cluster and takes back the library's SIGINT and SIGTERM handlers, as the e2e and browser harnesses do. runMain turns both into interruption, and the scope stops the server and Postgres. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…watches the cluster itself The retry polled on the test clock, which never advances, so a cluster still shutting down at the first check hung the case until its timeout. The cluster probe now spawns with node:child_process, since Effect's spawner signals a failed child's process group and could stop Postgres in the hook's place, and a pid finalizer cleans up after a failing run. The child takes its values as arguments rather than JSON in the script. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…up again Taking the library's SIGINT and SIGTERM handlers back as it loaded left no way out while Postgres was starting: acquisition can't be interrupted, and the release that stops the cluster doesn't exist until it succeeds, so a signal only queued an interruption. The handlers now stay until the cluster is up, as on main, and go as the next step, so the scope owns every later phase. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…times out Its cleanup is registered as soon as it spawns: it SIGKILLs the probe and the cluster named in the data directory's postmaster.pid, and waits for both before the directory goes. It still runs after the assertions, so it can't be what stopped Postgres. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-up. The cleanup read postmaster.pid once, so a case that timed out after Postgres was spawned but before it wrote that file killed only the probe and left Postgres running. The probe now leads its own process group, which initdb and Postgres join, and the finalizer interrupts the group, so Postgres frees its shared memory, then kills whatever ignored that. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
11d063e to
982aab0
Compare
Acceptance: PASS with notesChecked Done means
Golden journeys
Rollback answers: They match the diff and the observed behavior. The same dev cluster opened on 18.4 → 18.6 → 18.4 → 18.6. Ada published a page on each version, and Ben could read both pages after rollback and after upgrading again. Not run
Notes
|
What changed
embedded-postgresgoes from 18.4.0-beta.17 to 18.6.0-beta.19, the bump #1424 left out. The newest release is 18.6.0-beta.19, published on 2026-10-30. It and its eight platform packages ship Postgres 18.6, up from 18.4, so the dev instance, the Vitest Postgres template, the postgres-concurrency suite, the browser suites, the packed CLI e2e and the rollback rehearsal now run on 18.6. This is dev and test infrastructure only. People using Patchy notice nothing, and production Postgres doesn't come from this package.Look at
The shutdown hook changed library, and exit-hook needs a small patch to behave as before. embedded-postgres stops its clusters from a process-exit hook. 18.4 used
async-exit-hook, whichpatches/[email protected]fixed so a failed Vitest run kept its exit code. 18.6 usesexit-hook5, which keepsprocess.exitCodeon its own, so that patch and itspatchedDependenciesentry are gone. Nothing else in the tree resolves async-exit-hook, and pnpm refuses an unused patch.exit-hook differs from async-exit-hook in three ways that matter here. I measured them with a small script that loads embedded-postgres, starts a cluster and exits one way. "Cluster left" means Postgres was still running, with its
postmaster.pid, once the process had gone. Node 24 and Bun 1.4.4 gave the same results.exitCodeunset /= 1process.exit(3)with a cluster runningSYNCHRONOUS TERMINATION NOTICE…on stderrprocess.exit(3)after stopping itThe notice is the visible one. It would print whenever a process that loaded embedded-postgres ends through
process.exit()or an uncaught error, which includes packed-cli-e2e's failure and cancel paths and the rollback rehearsal's cancel path.patches/[email protected]restores async-exit-hook's behaviour on those paths:process.exit(), the hook starts the asynchronous callbacks too, unawaited. embedded-postgres'sstop()sends Postgres SIGINT before its firstawait, so the cluster still shuts down.scripts/dev/src/postgres.test.ts, which already pinned the exit-code fix, now covers both.The first new case starts a cluster in a child process that calls
process.exit(5)with it running. It checks the code, an empty stderr, and that the postmaster's pid is gone. The child is spawned with Node's ownspawn, because Effect's spawner signals a child's process group when it exits non-zero, and that could stop Postgres in the hook's place. Nothing in the test signals Postgres before those checks.Its cleanup is registered as soon as the probe spawns, before anything waits. The probe leads its own process group, which initdb and Postgres join, and the cleanup interrupts that group, so Postgres shuts down and frees its shared memory, then SIGKILLs whatever is left after 3 s and waits up to 5 s more for the group to empty. It doesn't depend on
postmaster.pid, so it also reaches a cluster that was spawned but hasn't written that file. It's a scope finalizer added after the temporary directory, so it runs after the assertions, including on failure and timeout, and before the directory is removed. A spawn error fails the case.The group cleanup was run outside the suite against three stalls: a probe that never exits with its cluster running (stopped by the interrupt in 250 ms), a timeout while the cluster is still starting (the same), and a Postgres frozen with SIGSTOP right after spawn (SIGKILLed at 3.3 s). Each left the group empty. A frozen Postgres can't act on the interrupt, so that last case leaves its shared-memory segment behind, as any SIGKILL of Postgres does.
The second case checks that a hangup exits 129.
All three cases run on live services (
excludeTestServices: true). The first version polled onit.effect's test clock, which never advances: whenever the first check found Postgres still shutting down, the retry never woke. That was the 30 s timeout CI and the loaded local suite hit.With only the patch's async-callback hunk removed, keeping notice suppression and SIGHUP, the first case fails, and its cleanup still leaves no cluster:
With the whole patch, all three pass, on 18.6 and on 18.4 alike. Without the patch at all, the SIGHUP case fails too, since the process dies by the signal instead of exiting 129.
Who stops the dev supervisor on SIGINT and SIGTERM. exit-hook forces its process out five seconds after either signal, where async-exit-hook allowed ten. The supervisor gives its server five seconds after SIGTERM before SIGKILL, so once the server runs, the hook could end the supervisor in the middle of its own teardown. So the two phases have different owners:
acquireReleaseacquisition, which can't be interrupted, and Postgres's release finalizer doesn't exist until it succeeds. The library's handlers stop the starting cluster and exit within exit-hook's bound, as on main, where it was async-exit-hook's.NodeRuntime.runMainturns both signals into interruption, and the scope stops the server and then Postgres.The library's exit,
beforeExitand SIGHUP hooks stay throughout.Manual runs on the real supervisor. SIGSTOP pauses a process so it acts on no SIGTERM, though SIGKILL still works, and it acts on a pending signal once resumed.
postmaster.pid(still starting), SIGTERM, Postgres resumed at 8 spostmaster.pidpostgres stopped; server SIGKILLed at its 5 s grace; nothing leftpostgres stopped, nothing leftA Postgres that stays paused forever during start-up would still be left, paused with the SIGINT it was sent, as on main. Only SIGKILL ends a stopped process, and embedded-postgres keeps its child private.
These aren't tests because they need the whole supervisor (plan, server, cluster). SIGHUP isn't fixed by this: exit-hook's hangup handler still exits before the finalizers, and
runMainroutes only SIGINT and SIGTERM. So the SIGHUP row below is unchanged from main.The exit paths, before (main, 18.4) and after (this branch). Each ran on this machine, on Node 24.20.0, against throwaway instances. The dev rows ran again on this head, and the other rows don't involve the supervisor. "Stopped" means no postgres or server process was left and no
postmaster.pidremained. "Notices" countsSYNCHRONOUS TERMINATION NOTICEin the full output.scripts/dev/src/postgres.test.ts)pnpm dev stop(SIGTERM to the supervisor)postgres stoppedlogged)pnpm dev down--live origin/main, successThe rehearsal ran with
--live origin/main, so it compares main with this branch and never reads production's health endpoint.IPC. Both hook libraries add the same
process.on("message")listener, which acts only on the string"shutdown"(pm2's). Our code opens no IPC channel to a process that loads embedded-postgres. The only channels there are Playwright's workers and Vitest's fork pool, which send structured messages, and the browser and test suites pass.What Postgres 18.4 to 18.6 changes for us (release notes; 18.5 was never released). It needs no dump or restore within 18, so a worktree's existing
.local/devcluster opens as it is. It's mostly security and crash fixes.Notes that touch what we use:
reltuplescorrectly. The feedback search tables have GIN indexes. This only affects planner statistics, and dev and test databases are small and fresh.CREATEnow takes a shared lock on the objects it depends on, so a concurrentDROPof the schema it lands in fails one side instead of leaving a broken object.40001.postgres-concurrency, which exercises provisioning, reclamation and those transactions, passes. The release's other headline changes (logical-decoding output-plugin allowlist, pgcrypto ciphers, psql
COPY) touch nothing we use.allowBuilds. 18.6 installs the same eight
@embedded-postgres/*platform packages, each with ahydrate-symlinkspostinstall thatallowBuildsalready permits. The new start-upensureSymlinkscheck passes on the installed linux-x64 build.Docs.
docs/DEVELOPMENT.mdand thepatchy-dev-loopskill don't describe the hook workaround, so they don't change. Thepnpm-workspace.yamlcomment and packed-cli-e2e's import comment now name exit-hook. The other comments about embedded-postgres's process-exiting handlers (devmain.ts, the rollback rehearsal, the browser instances) stay true.How it was verified
pnpm verifyon Node 24.20.0, on the first push (d144206): format, lint, synth, postgres-concurrency, cli-smoke, install, tier2-smoke and browser (Chromium 187 of 187 and Firefox 10 of 10) passed, with no termination notice anywhere in the output, Playwright's workers included.typecheckfailed on theJSON.stringifythe old test used.testandtest (bun)failed only on that test's frozen-clock timeout. On this head,pnpm testpasses 3,615 of 3,615 andpnpm test:bun3,296 with 3 skipped, again with no notice. The supervisor changes touch onlypnpm dev, whose paths ran again above.pnpm format:check,pnpm lintandpnpm typecheck(all 25 tasks, including@patchy/dev's own check of its test files under the base rules): clean on this head.Unchanged and worth knowing, not fixed here.
pnpm dev stopanddownsend SIGTERM, which doesn't hit this.Error: kill ESRCHfrom its own cluster finalizer, before and after.Small differences the patch leaves, in processes that keep embedded-postgres's signal handlers (the Vitest global setup,
HandlerTls.test.ts, the server image smoke):Release impact
A dev and test dependency and one dependency patch. No product code, API, schema or CLI change.
Made by Claude Opus 5.5 in T3 Code via Claude Code.
🤖 Generated with Claude Code