Skip to content

Commit 814369e

Browse files
committed
Enable graceful shutdown by default
Closes gh-37495
1 parent 543bb80 commit 814369e

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public class ServerProperties {
109109
/**
110110
* Type of shutdown that the server will support.
111111
*/
112-
private Shutdown shutdown = Shutdown.IMMEDIATE;
112+
private Shutdown shutdown = Shutdown.GRACEFUL;
113113

114114
@NestedConfigurationProperty
115115
private Ssl ssl;

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ void sessionStoreDir() {
186186
@Test
187187
void whenShutdownPropertyIsSetThenShutdownIsCustomized() {
188188
Map<String, String> map = new HashMap<>();
189-
map.put("server.shutdown", "graceful");
189+
map.put("server.shutdown", "immediate");
190190
bindProperties(map);
191191
ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
192192
this.customizer.customize(factory);
193-
then(factory).should().setShutdown(assertArg((shutdown) -> assertThat(shutdown).isEqualTo(Shutdown.GRACEFUL)));
193+
then(factory).should().setShutdown(assertArg((shutdown) -> assertThat(shutdown).isEqualTo(Shutdown.IMMEDIATE)));
194194
}
195195

196196
private void bindProperties(Map<String, String> map) {

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/web/graceful-shutdown.adoc

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
11
[[web.graceful-shutdown]]
22
= Graceful Shutdown
33

4-
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.
4+
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.
55
It occurs as part of closing the application context and is performed in the earliest phase of stopping `SmartLifecycle` beans.
66
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.
77

8+
To configure the timeout period, configure the configprop:spring.lifecycle.timeout-per-shutdown-phase[] property, as shown in the following example:
9+
10+
[configprops,yaml]
11+
----
12+
spring:
13+
lifecycle:
14+
timeout-per-shutdown-phase: "20s"
15+
----
16+
17+
NOTE: Graceful shutdown with Tomcat requires Tomcat 9.0.33 or later.
18+
19+
IMPORTANT: Shutdown in your IDE may be immediate rather than graceful if it does not send a proper `SIGTERM` signal.
20+
See the documentation of your IDE for more details.
21+
22+
23+
24+
[[web.graceful-shutdown.rejecting-requests-during-the-grace-period]]
25+
== Rejecting Requests During the Grace Period
26+
827
The exact way in which new requests are not permitted varies depending on the web server that is being used.
928
Implementations may stop accepting requests at the network layer, or they may return a response with a specific HTTP status code or HTTP header.
1029
The use of persistent connections can also change the way that requests stop being accepted.
1130

12-
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)[].
31+
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)[].
1332

1433
Jetty, Reactor Netty, and Tomcat will stop accepting new requests at the network layer.
1534
Undertow will accept new connections but respond immediately with a service unavailable (503) response.
1635

17-
NOTE: Graceful shutdown with Tomcat requires Tomcat 9.0.33 or later.
1836

19-
To enable graceful shutdown, configure the configprop:server.shutdown[] property, as shown in the following example:
2037

21-
[configprops,yaml]
22-
----
23-
server:
24-
shutdown: "graceful"
25-
----
38+
[[web.graceful-shutdown.disabling-graceful-shutdown]]
39+
== Disabling Graceful Shutdown
2640

27-
To configure the timeout period, configure the configprop:spring.lifecycle.timeout-per-shutdown-phase[] property, as shown in the following example:
41+
To disable graceful shutdown, configure the configprop:server.shutdown[] property, as shown in the following example:
2842

2943
[configprops,yaml]
3044
----
31-
spring:
32-
lifecycle:
33-
timeout-per-shutdown-phase: "20s"
45+
server:
46+
shutdown: "immediate"
3447
----
35-
36-
IMPORTANT: Using graceful shutdown with your IDE may not work properly if it does not send a proper `SIGTERM` signal.
37-
See the documentation of your IDE for more details.

0 commit comments

Comments
 (0)