feat(backend): graceful shutdown on SIGTERM/SIGINT

Run the HTTP server in a goroutine and, on SIGINT/SIGTERM, call
srv.Shutdown so it stops accepting connections and lets in-flight
requests finish before exiting (ErrServerClosed is a clean exit). This
stops uploads/streams being cut when the container is stopped or
recreated on deploy.

The drain deadline is configurable via SHUTDOWN_TIMEOUT (default 15s).
docker-compose.yml feeds the same variable into the app's
stop_grace_period, so Docker won't SIGKILL mid-drain and the two values
can't drift.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 08:12:10 +03:00
parent bf7fa49a16
commit a6a46af12e
4 changed files with 55 additions and 3 deletions
+6
View File
@@ -26,6 +26,12 @@ services:
container_name: tfm
restart: unless-stopped
# Give the app time to drain in-flight requests on stop before SIGKILL. Reads
# the same SHUTDOWN_TIMEOUT the app uses for its graceful-shutdown deadline
# (via env_file below), so the two never drift. Interpolated from .env at
# `docker compose` time; defaults to 15s if unset.
stop_grace_period: ${SHUTDOWN_TIMEOUT:-15s}
# All application config (secrets, DATABASE_URL, tunables) comes from .env.
env_file: .env