Repository navigation
fix: the bundled PostgreSQL shuts down cleanly when the container stops - #541
Merged
Merged
Conversation
supervisord stopped PostgreSQL with SIGTERM (smart shutdown), which waits for every client. node keeps its connections open, so PostgreSQL was SIGKILLed at supervisord's 10 s default and every start ran crash recovery. - [program:postgresql]: stopsignal=INT (fast shutdown) and stopwaitsecs=60 - stop_grace_period: 90s in docker-compose.yml, docker-compose.local.yml, the README compose example and the unified.md examples (docker run --stop-timeout 90) - docs: Shutdown Sequence in deployment/unified.md, Fixed Issue 22, TOC line - tests/docker/supervisord-config.test.ts Based on #512 by @drwho725. Co-authored-by: drwho725 <887768+drwho725@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d in the standard compose example Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Every stop, restart or update of the unified container killed the bundled PostgreSQL, so the next start logged
database system was not properly shut down; automatic recovery in progressand ran crash recovery. supervisord stopped PostgreSQL with SIGTERM, which is PostgreSQL's smart shutdown: it waits for every client to disconnect. node keeps its database connections open during a stop, so PostgreSQL never finished and was SIGKILLed at supervisord's 10 s default (or by Docker at its own 10 s).PostgreSQL now stops with SIGINT (fast shutdown: it ends open sessions, writes a checkpoint and exits) and gets up to 60 s to do it. A normal stop takes about 1-2 s, well inside Docker's default 10 s, so existing installs get the fix from the image alone. The compose files and examples also set
stop_grace_period: 90sfor headroom on slow storage.Based on #512 by @drwho725.
Changes
docker/unified/supervisord.conf:[program:postgresql]getsstopsignal=INTandstopwaitsecs=60, with a short comment. Nothing else changes: supervisord already stops programs in reverse priority (app, then Redis, then PostgreSQL) andpostgres-start.shalreadyexecs postgres, so the signal reaches PostgreSQL directly.stop_grace_period: 90sindocker-compose.yml,docker-compose.local.ymland the README compose example;documentation/deployment/unified.mdcompose examples anddocker run --stop-timeout 90example. 90 s is above the 80 s worst case (10 + 10 + 60).documentation/deployment/unified.md(order, settings, grace period, Unraid, what a clean stop logs, the one recovery after updating), Fixed Issue 22, TABLEOFCONTENTS line.Evidence
Same container, stopped and started twice per image,
--network none, a health request right before each stop so node holds a DB connection. Shutdown counts are from the lines written during the stop; recovery counts from the next start.docker stop --time 10(Docker's default)docker stop --time 90docker stop --time 10docker stop --time 90Upgrade path (named volumes for the database and
/app/config): a volume last stopped by the old image recovers once on the first start of the new image, as expected, since that was the old image's stop. The new image's own stop/start after that: fast shutdown in 1.8 s, exit 0, no recovery.The PostgreSQL and supervisord lines from every cycle: https://gist.github.com/kikootwo/5f68c04e4bf8acd0370f7fbd7fdc5d38
Tests
tests/docker/supervisord-config.test.ts: PostgreSQLstopsignal=INT,stopwaitsecs>= 30,postgres-start.shexecs postgres, and the grace period in both compose files and the README is above the summedstopwaitsecs. Against main's files 5 of its 6 tests fail (theexeccheck passes on both).docker-compose*.yml) and never skip on GitHub Actions.Checks
npx vitest run tests/docker/supervisord-config.test.ts tests/docker/node-version-pins.test.ts: 12/12npx tsc --noEmit: cleannpx eslint tests/docker/supervisord-config.test.ts: 0 errors, 0 warningsdockerfile.unified): OKRisk and rollback
stop_grace_period: 90sDocker now waits up to 90 s instead of 10 s before killing it. Same outcome as before, only slower.FATAL: terminating connection due to administrator commandfor each open session, and node may log Prisma connection errors before the container exits. Cosmetic. node still does not receive SIGTERM throughapp-start.shand is killed when the container exits, as before; that is a separate issue: Unified image: node never receives SIGTERM when the container stops #540.USE_EXTERNAL_POSTGRES=true: the program isexec sleep infinity, which SIGINT ends exactly like SIGTERM did.🤖 Generated with Claude Code