Implement graceful shutdown for web server on SIGTERM/SIGINT - #207
Open
Just-Bamford wants to merge 2 commits into
Open
Implement graceful shutdown for web server on SIGTERM/SIGINT#207Just-Bamford wants to merge 2 commits into
Just-Bamford wants to merge 2 commits into
Conversation
Contributor
|
please ensure all checks pass |
- Register SIGTERM/SIGINT handlers in index.js startServer() - Stop accepting new connections via server.close() - Drain in-flight requests before shutdown - Close config poller interval/worker cleanly - Close database pool gracefully with proper cleanup - Set 30-second timeout to prevent infinite hangs - Remove automatic shutdown handlers from db/client.js - Mirrors proven pattern from event-worker.js Fixes deploy/restart safety for rolling deployments and container restarts.
Just-Bamford
force-pushed
the
fix/issue--server-graceful-shutdown
branch
from
August 23, 2026 10:06
4b71697 to
ab346a7
Compare
Author
|
@N-thnI kindly review |
Author
|
@N-thnI haffa just close the issue |
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.
Description
Problem
The web server in
index.jswas not implementing graceful shutdown handlers for SIGTERM/SIGINT signals. During rolling deploys or container restarts:Closes #199
This created data integrity risks and violated deploy best practices. The event worker (
src/workers/event-worker.js) already had the correct graceful shutdown pattern implemented (lines 182-211), but this safety mechanism was missing from the web server process.Solution
Applied the existing graceful shutdown pattern from
event-worker.jsto the web server'sstartServer()function inindex.js. The implementation now:startServer()functionserver.close()process.exit(0)Changes Made
index.jsstopConfigPollerfrom./src/services/config-pollersrc/db/client.jsto include theshutdownfunction (aliased asshutdownDbPool)shutdown(signal)handler withinstartServer()that:closingflagserver.close()to stop accepting new connectionssrc/db/client.jsshutdown()function is now explicitly called by the server's shutdown handler rather than being triggered implicitlyBehavior
Before: Container receives SIGTERM → process exits immediately → in-flight requests dropped, pool closes abruptly
After: Container receives SIGTERM → server stops accepting new connections → existing requests complete → config poller stops → db pool drains cleanly → process exits with code 0
Verification
event-worker.jsAcceptance Criteria Met
✓ SIGTERM sent to running server drains in-flight requests before exiting
✓ Database pool closes cleanly
✓ Config poller stops cleanly
✓ Behavior mirrors
event-worker.jsshutdown pattern✓ 30-second timeout prevents infinite hangs
✓ Error logging for debugging shutdown issues