feat(backend): add graceful shutdown for HTTP and WebSocket servers (#170)#195
Merged
Merged
Conversation
Handle SIGTERM and SIGINT by draining in-flight HTTP requests, closing the WebSocket and Redis connections, and exiting with a code that reflects whether the drain finished within the grace period. - add src/utils/shutdown.ts: a dependency-injected shutdown coordinator with ordered cleanup steps, a grace period configurable via GRACEFUL_SHUTDOWN_TIMEOUT_MS (default 30s), exit 0 on a clean drain and 1 on timeout, a shutdownGuard middleware that returns 503 for new requests during drain, and an isShuttingDown flag - wire the coordinator into src/index.ts, replacing the partial SIGINT stub; register WebSocket, HTTP drain, transaction worker, and Redis cleanup steps; report "shutting down" (503) from /api/health - add WebsocketService.close(): notify clients with a "server shutting down" message and disconnect sockets so the shared HTTP server can finish draining - add src/__tests__/shutdown.test.ts (10 tests, 100% line coverage of the new module) Closes AetherEdu#170
Penielka
approved these changes
Jun 28, 2026
7 tasks
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
Implements #170: graceful shutdown for the HTTP and WebSocket servers. On
SIGTERM or SIGINT the process stops accepting new traffic, drains in-flight
requests within a configurable grace period, closes the WebSocket and Redis
connections, and exits with code 0 on a clean drain or 1 on timeout.
Changes
Definition of Done
Testing
Closes #170