At the moment, graceful shutdown is triggered directly by the reactive and servlet application contexts. This works well in isolation but has some drawbacks when other components want to participate in a graceful shutdown. Some of these drawbacks are described by @gnagy in https://github.com/spring-projects/spring-boot/issues/4657#issuecomment-623304269.
We'd like to explore reworking the management of a WebServer
's lifecycle and integrating it with the application context's lifecycle processing by implementing SmartLifecycle
. This would make the grace period that's currently configured via server.shutdown.grace-period
more general . server.shutdown.grace-period
could be replaced by a new property, spring.lifecycle.timeout-per-shutdown-phase
, that maps onto the timeoutPerShutdownPhase
property of DefaultLifecycleProcessor
. We'd then need a new property that can be used to make the web server opt in to graceful shutdown rather than shutting down immediately as it does in 2.2. Something like server.shutdown.type
that is a enum with IMMEDIATE
and GRACEFUL
values.
Comment From: sagacity
This would be great to have. We've currently added this to our applications ourselves by following the approach taken in https://github.com/SchweizerischeBundesbahnen/springboot-graceful-shutdown but it was reasonably invasive (requiring a different application class to 'wrap' the real application).
Having proper support would be great! It would be good if command-line applications (e.g. used as cronjobs) can also use the IMMEDIATE
shutdown option. This would allow them to shut down cleanly while still being able to flush async logging etc. Since these types of apps don't typically need a webserver it would be very nice if this shutdown behaviour can be decoupled from the webserver part.