Repository navigation
Migration-safe update: keep the health wait alive during migrations - #85
Merged
Merged
Conversation
The 0.8.0 install lost its first start because the launcher's 60 s health deadline expired while migrations ran for 181 to 220 s on a 4.3 GB database. The launcher killed the server mid-migration and systemd restarted it to repeat the work. - The health deadline slides while the migrating lock's info file names a live process, so it expires 60 s after the migration ends, never during it. Progress is logged every 10 s and the wait is capped at one hour. - migrate() holds the lock and info file through backup finalization (phase finalizing), which otherwise ran unmarked for over a minute. - The lock removes its info file on release; the helpers moved to @bb/config/migration-info so bb-app can read them. - Stopping during a migration waits for it instead of killing after 5 s. - The generated systemd unit sets TimeoutStopSec=3900. Tracked in bead mk-ooomf.1. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A SIGTERM during a migration killed it even with a long TimeoutStopSec, because systemd signals the whole control group and the server only installed its handlers after the database opened. The server now records SIGTERM/SIGINT before it opens the database, finishes the migration, and exits cleanly before listening. A migration marker left by a crashed process could look active when its pid was reused, extending the health wait for up to an hour. The marker now records the holder's process identity (boot id plus start time on Linux); readActiveMigration rejects dead pids, changed identities and markers older than the cap, and the launcher requires the marker pid to equal the server process it spawned. Bead mk-ooomf.1. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The server now publishes a startup marker before it installs its stop guard, so the launcher can see a deferred stop even when SIGTERM lands before the migrating marker is written. The launcher also rechecks the database state at the 5 s mark and waits instead of escalating to SIGKILL when a marker appeared after it signalled. Marker liveness checks are shared between migration and startup markers. The pid-reuse tests in the config package now use a synthetic recorded identity so they pass without /proc. Bead: mk-ooomf.1 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Startup markers were one shared file per database, so a second startup could overwrite or remove the first's marker and leave the launcher without protection at its 5 s recheck. Each process now writes and removes only <db>.starting.<pid>.info, and the launcher reads the file for the pid it spawned. The launcher termination test uses fileURLToPath and is skipped on win32, where SIGTERM is a hard kill. Bead: mk-ooomf.1 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The overlap test now resolves the child script and cwd with fileURLToPath, is skipped on win32 (POSIX signals), and rejects its startup wait when the child errors or exits early. readActiveStartup deletes a per-pid startup marker whose owner is dead or overdue; a live owner's marker is kept. Bead: mk-ooomf.1 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Reverts the reader-side deletion in readActiveStartup: unlinking after a read could remove a fresh marker published by a reused pid. Dead or overdue markers are ignored as before, and the possible accumulation is documented in FORK.md as a known non-blocking limitation. runStoppedChild now rejects when the child errors or exits before "started", and both tests that send POSIX signals are skipped on win32. Bead: mk-ooomf.1 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
Why
In the 0.8.0 install the launcher's 60 s health timeout expired while migrations on a 4.3 GB database took about 181-220 s. The launcher killed the server mid-migration and systemd (
Restart=always) re-ran the migration. Tracked in bead mk-ooomf.1 (epic mk-ooomf).What changed
@bb/config/migration-info(new): shared helpers for the<db>.migrating.lock/<db>.migrating.infomarkers (readActiveMigration,isProcessAlive,MIGRATION_WAIT_CAP_MS= 1 h).migrate()holds the lock and info file through backup finalization (new phasefinalizing). Before, the marker disappeared while a 5 GB backup was still being digested, which is what made the first rehearsal fail at 169 s. The info file is now unlinked on release.apps/server/src/startup-stop-guard.ts), so a stop during a migration lets it finish and exit cleanly. Previously systemd's SIGTERM killed it even withTimeoutStopSec=3900./procon Linux).readActiveMigrationignores a marker whose pid is dead, whose identity changed (pid reuse), or that is older than the cap. The launcher also requires the marker pid to equal the server process it spawned.<db>.starting.<pid>.info(pid and process identity; each process writes and removes only its own file, and the launcher reads the file for the pid it spawned, so overlapping startups cannot clear one another) before it installs its handlers and removes it when startup settles, so a stop is visible to the launcher even before the migrating marker exists. The launcher waits for the cap when either marker is present, and rechecks at the 5 s mark so a marker that appeared after the signal still prevents SIGKILL. A server that publishes nothing is still killed at 5 s. The launcher now passes the database path on its health-failure termination path too.fileURLToPathand is skipped on win32./proc; one Linux-only test checks the real identity reader.install-machine.sh: generated unit getsTimeoutStopSec=3900.FORK.mdandCHANGELOG.mddocument the change, including the drop-in needed for already-installed units.Verification
TimeoutStopSec.migrate()as a transientRestart=alwayssystemd user unit with the 60 s timeout unchanged: migrate took 203.9 s, padded to 250.0 s, server healthy at 250.8 s,NRestarts=0. Control with the marker hidden failed at 60.09 s.systemctl --user stop65 s into the real migration. The server logged the deferred stop, finished migrating (203 s), exited 0,NRestarts=0, no leftover info file, and the next start had nothing to migrate (15 ms). The 250 s rehearsal re-passed with the new code (healthy at 251.8 s,NRestarts=0).systemctl --user stop80 s into the migration was deferred, migration finished (250 s with padding), exit 0,NRestarts=0, no SIGKILL, startup marker removed (stop took 158 s).Not verified
test/index.test.tshas 4 config-command failures; they exercise code this diff does not touch, but I could not compare against a clean baseline (stash was blocked by the destructive-git guard).migration-restore) timed out at 15 s under host load and passed on re-run alone.paths.tsv) is not updated.migrate()and the real stop guard, not the fullstart-server.ts.🤖 Generated with Claude Code