Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graceful shutdown #1889

tanner0101 opened this Issue Feb 12, 2019 · 3 comments


2 participants
Copy link

tanner0101 commented Feb 12, 2019

Vapor 4 has added support for capturing SIGINT to shut down the server. This is a great start, but we can do more to support graceful shutdown.

  • Use NIO's QuiescingHelper to give in-flight HTTP requests a chance to complete before closing the server.
  • Also capture SIGTERM signal to gracefully close server.
  • When app.cleanup() calls elg.syncShutdownGracefully(), NIO should close any remaining open channels (such as DB connections) if it needs to. However, it would be nice if by time the event loop shutdown, those connections were already closed. This could be achieved by allowing for service providers to register custom cleanup behavior.
  • Providers like Fluent should add support for Provider.willShutdown
  • Server quiescing should have a deadline.

@tanner0101 tanner0101 self-assigned this Feb 12, 2019

@tanner0101 tanner0101 added this to To Do in Vapor 4 via automation Feb 12, 2019


This comment has been minimized.

Copy link

weissi commented Feb 12, 2019

and here's a full demo HTTP server that does the whole thing for SIGINT:

@heckj heckj referenced this issue Feb 12, 2019


shutdown on SIGTERM as well as SIGINT #1890

4 of 4 tasks complete

This comment has been minimized.

Copy link
Member Author

tanner0101 commented Feb 15, 2019

QuiescingHelper added in vapor/http#330. I just copied it in for now, but once NIOExtras is updated to NIO 2, I will look into adding that as a dep. I've updated the original tasks to include adding a quiescing timeout.


This comment has been minimized.

Copy link
Member Author

tanner0101 commented Feb 15, 2019

When Vapor's running server stops, it now calls Container.willShutdown() on any containers it created. This gives container providers a chance to free up resources before they are deinitialized. Any containers created by other means should make sure to call container.willShutdown() before letting the container deinit.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.