-
Notifications
You must be signed in to change notification settings - Fork 40.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
29 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
42 changes: 26 additions & 16 deletions
42
...ng-boot-docs/src/docs/antora/modules/reference/pages/web/graceful-shutdown.adoc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
[[web.graceful-shutdown]] | ||
= Graceful Shutdown | ||
|
||
Graceful shutdown is supported with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and servlet-based web applications. | ||
Graceful shutdown is enabled by default with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and servlet-based web applications. | ||
It occurs as part of closing the application context and is performed in the earliest phase of stopping `SmartLifecycle` beans. | ||
This stop processing uses a timeout which provides a grace period during which existing requests will be allowed to complete but no new requests will be permitted. | ||
|
||
To configure the timeout period, configure the configprop:spring.lifecycle.timeout-per-shutdown-phase[] property, as shown in the following example: | ||
|
||
[configprops,yaml] | ||
---- | ||
spring: | ||
lifecycle: | ||
timeout-per-shutdown-phase: "20s" | ||
---- | ||
|
||
NOTE: Graceful shutdown with Tomcat requires Tomcat 9.0.33 or later. | ||
|
||
IMPORTANT: Shutdown in your IDE may be immediate rather than graceful if it does not send a proper `SIGTERM` signal. | ||
See the documentation of your IDE for more details. | ||
|
||
|
||
|
||
[[web.graceful-shutdown.rejecting-requests-during-the-grace-period]] | ||
== Rejecting Requests During the Grace Period | ||
|
||
The exact way in which new requests are not permitted varies depending on the web server that is being used. | ||
Implementations may stop accepting requests at the network layer, or they may return a response with a specific HTTP status code or HTTP header. | ||
The use of persistent connections can also change the way that requests stop being accepted. | ||
|
||
TIP: To learn about more the specific method used with your web server, see the `shutDownGracefully` API documentation for javadoc:org.springframework.boot.web.embedded.tomcat.TomcatWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[], javadoc:org.springframework.boot.web.embedded.netty.NettyWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[], javadoc:org.springframework.boot.web.embedded.jetty.JettyWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[] or javadoc:org.springframework.boot.web.embedded.undertow.UndertowWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[]. | ||
TIP: To learn more about the specific method used with your web server, see the `shutDownGracefully` API documentation for javadoc:org.springframework.boot.web.embedded.tomcat.TomcatWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[], javadoc:org.springframework.boot.web.embedded.netty.NettyWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[], javadoc:org.springframework.boot.web.embedded.jetty.JettyWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[] or javadoc:org.springframework.boot.web.embedded.undertow.UndertowWebServer#shutDownGracefully(org.springframework.boot.web.server.GracefulShutdownCallback)[]. | ||
|
||
Jetty, Reactor Netty, and Tomcat will stop accepting new requests at the network layer. | ||
Undertow will accept new connections but respond immediately with a service unavailable (503) response. | ||
|
||
NOTE: Graceful shutdown with Tomcat requires Tomcat 9.0.33 or later. | ||
|
||
To enable graceful shutdown, configure the configprop:server.shutdown[] property, as shown in the following example: | ||
|
||
[configprops,yaml] | ||
---- | ||
server: | ||
shutdown: "graceful" | ||
---- | ||
[[web.graceful-shutdown.disabling-graceful-shutdown]] | ||
== Disabling Graceful Shutdown | ||
|
||
To configure the timeout period, configure the configprop:spring.lifecycle.timeout-per-shutdown-phase[] property, as shown in the following example: | ||
To disable graceful shutdown, configure the configprop:server.shutdown[] property, as shown in the following example: | ||
|
||
[configprops,yaml] | ||
---- | ||
spring: | ||
lifecycle: | ||
timeout-per-shutdown-phase: "20s" | ||
server: | ||
shutdown: "immediate" | ||
---- | ||
|
||
IMPORTANT: Using graceful shutdown with your IDE may not work properly if it does not send a proper `SIGTERM` signal. | ||
See the documentation of your IDE for more details. |