fix: Add configurable shutdown grace period for graceful server termination - #1103
Merged
Conversation
On SIGTERM the close-with-grace callback could hang past the default 10s delay - the same as Docker's default stop grace period - so the container was routinely SIGKILLed after ~10s instead of exiting cleanly. Two causes: - app and adminApp each had an onClose hook closing the other, so app.close() could re-enter adminApp.close() (and vice versa) while it was already in progress and never settle. closeWithGrace already closes both apps, so drop the hooks. - Each close step rethrew on failure, aborting the remaining cleanup. Log and continue instead so one failing step can't block the rest. Also lower the close-with-grace delay to 1.5s so a close that still hangs (e.g. on a stuck in-flight request) force-exits well before the container runtime's SIGKILL. Verified locally: clean SIGTERM exits in ~20ms with code 0; with a held in-flight request the process force-exits at 1.5s instead of hanging 10s. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gj9ospbnecaS2ccYt2MayL
Replace the hardcoded 1.5s close-with-grace delay with PG_META_SHUTDOWN_GRACE_PERIOD_SECS, defaulting to 10s (close-with-grace's own default, so production behavior is unchanged). Local dev and deployments with a longer container stop grace period can lower it to get fast, clean shutdowns. Verified locally: with a held in-flight request, SIGTERM force-exits at ~2s with PG_META_SHUTDOWN_GRACE_PERIOD_SECS=2 and at ~10s when unset. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gj9ospbnecaS2ccYt2MayL
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gj9ospbnecaS2ccYt2MayL
🚀 Canary Deployment Status✅ Canary image deployed successfully! 🐳 Docker Image: You can test this canary deployment by pulling the image: docker pull supabase/postgres-meta:canary-pr-1103-ed09961448b2c30498c9b6d98de4e3e88252fd84You can also set the version in a supabase local project by running: echo "supabase/postgres-meta:canary-pr-1103-ed09961448b2c30498c9b6d98de4e3e88252fd84" > supabase/.temp/pgmeta-versionOr use it in your docker-compose.yml: services:
postgres-meta:
image: supabase/postgres-meta:canary-pr-1103-ed09961448b2c30498c9b6d98de4e3e88252fd84
# ... other configurationThe canary image is available on: false Last updated: 2026-08-14T13:31:48Z |
avallete
enabled auto-merge
August 14, 2026 15:48
mandarini
approved these changes
Aug 14, 2026
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
Refactors the server shutdown logic to use a configurable grace period before force-exiting, allowing in-flight work to complete within a timeout window. This improves reliability in containerized environments where the container runtime may SIGKILL the process after its own grace period.
Key Changes
PG_META_SHUTDOWN_GRACE_PERIOD_SECS(default: 10 seconds) controls how long the server waits for in-flight work before force-exiting.catch()for graceful error handling during shutdown instead of throwing, ensuring all cleanup steps attempt to runerrorlevel toinfolevel (more appropriate for normal shutdown signals)Implementation Details
closeWithGracecall now passes adelayoption set toSHUTDOWN_GRACE_PERIOD_MScloseListenersvariable and associated hook uninstall logic that was managing listener lifecycleapp.onCloseandadminApp.onClosehooks that could prevent proper shutdown.catch()to log errors without throwing, ensuring subsequent cleanup steps executehttps://claude.ai/code/session_01Gj9ospbnecaS2ccYt2MayL