Skip to content

fix(#149): drain HTTP, Socket.IO, and DB work on graceful shutdown - #154

Merged
Tybravo merged 1 commit into
SwiftChainn:mainfrom
spiffamani:fix/graceful-shutdown-drain
Aug 28, 2026
Merged

fix(#149): drain HTTP, Socket.IO, and DB work on graceful shutdown#154
Tybravo merged 1 commit into
SwiftChainn:mainfrom
spiffamani:fix/graceful-shutdown-drain

Conversation

@spiffamani

Copy link
Copy Markdown

Summary

  • Centralize SIGTERM/SIGINT handling in GracefulShutdownService so the server stops accepting new HTTP/Socket.IO work, drains in-flight requests, disconnects Socket.IO clients, waits for tracked MongoDB sessions, then closes the DB pool before exit.
  • Remove the competing SIGINT handler in database.ts that could exit before sockets/HTTP finished draining.
  • Add request-tracker middleware (503 during drain), tracked DB sessions for transactional work, and unit tests covering the shutdown sequence.

Closes #149

Test plan

  • pnpm exec jest tests/gracefulShutdown.test.ts --runInBand (5 tests passed)
  • Manually start the server, open a Socket.IO client, send SIGTERM, confirm logs show HTTP close → socket drain → DB disconnect → clean exit
  • Confirm a mid-request does not get cut off abruptly when SIGTERM is sent
  • Confirm new HTTP requests receive 503 after shutdown begins

…shutdown

Stop accepting new requests on SIGTERM/SIGINT, wait for in-flight HTTP and tracked Mongo sessions, disconnect Socket.IO clients, then close the DB pool before exit.

Co-authored-by: Cursor <[email protected]>
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@spiffamani Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Tybravo
Tybravo merged commit 8939324 into SwiftChainn:main Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Ensure Graceful Shutdown logic correctly drains active Socket.io connections and DB transactions

2 participants