Skip to content

Commit 2a843d1

Browse files
committed
Set Reactor Netty's shutdownQuietPeriod to 0 when using devtools
See gh-33855
1 parent 53f0840 commit 2a843d1

File tree

8 files changed

+133
-23
lines changed

8 files changed

+133
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.reactor.netty;
18+
19+
import java.time.Duration;
20+
21+
import org.springframework.boot.context.properties.ConfigurationProperties;
22+
23+
/**
24+
* Configuration properties for Reactor Netty configuration.
25+
*
26+
* @author Moritz Halbritter
27+
* @since 2.7.9
28+
*/
29+
@ConfigurationProperties(prefix = "spring.reactor.netty")
30+
public class ReactorNettyConfigurationProperties {
31+
32+
/**
33+
* Configure the amount of time to wait before shutting down resources.
34+
*/
35+
private Duration shutdownQuietPeriod;
36+
37+
public Duration getShutdownQuietPeriod() {
38+
return this.shutdownQuietPeriod;
39+
}
40+
41+
public void setShutdownQuietPeriod(Duration shutdownQuietPeriod) {
42+
this.shutdownQuietPeriod = shutdownQuietPeriod;
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.reactor.netty;
18+
19+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
20+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
21+
import org.springframework.context.annotation.Bean;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.http.client.reactive.ReactorResourceFactory;
24+
25+
/**
26+
* Configurations for Reactor Netty. Those should be {@code @Import} in a regular
27+
* auto-configuration class.
28+
*
29+
* @author Moritz Halbritter
30+
* @since 2.7.9
31+
*/
32+
public final class ReactorNettyConfigurations {
33+
34+
private ReactorNettyConfigurations() {
35+
}
36+
37+
@Configuration(proxyBeanMethods = false)
38+
@EnableConfigurationProperties(ReactorNettyConfigurationProperties.class)
39+
public static class ReactorResourceFactoryConfiguration {
40+
41+
@Bean
42+
@ConditionalOnMissingBean
43+
ReactorResourceFactory reactorResourceFactory(ReactorNettyConfigurationProperties configurationProperties) {
44+
ReactorResourceFactory reactorResourceFactory = new ReactorResourceFactory();
45+
if (configurationProperties.getShutdownQuietPeriod() != null) {
46+
reactorResourceFactory.setShutdownQuietPeriod(configurationProperties.getShutdownQuietPeriod());
47+
}
48+
return reactorResourceFactory;
49+
}
50+
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Auto-configuration for Reactor Netty.
19+
*/
20+
package org.springframework.boot.autoconfigure.reactor.netty;

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3333
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3434
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
35+
import org.springframework.boot.autoconfigure.reactor.netty.ReactorNettyConfigurations;
3536
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3637
import org.springframework.boot.context.properties.PropertyMapper;
3738
import org.springframework.boot.rsocket.context.RSocketServerBootstrap;
@@ -41,6 +42,7 @@
4142
import org.springframework.context.annotation.Bean;
4243
import org.springframework.context.annotation.Conditional;
4344
import org.springframework.context.annotation.Configuration;
45+
import org.springframework.context.annotation.Import;
4446
import org.springframework.core.io.buffer.NettyDataBufferFactory;
4547
import org.springframework.http.client.reactive.ReactorResourceFactory;
4648
import org.springframework.messaging.rsocket.RSocketStrategies;
@@ -79,14 +81,9 @@ RSocketWebSocketNettyRouteProvider rSocketWebsocketRouteProvider(RSocketProperti
7981
@ConditionalOnProperty(prefix = "spring.rsocket.server", name = "port")
8082
@ConditionalOnClass(ReactorResourceFactory.class)
8183
@Configuration(proxyBeanMethods = false)
84+
@Import(ReactorNettyConfigurations.ReactorResourceFactoryConfiguration.class)
8285
static class EmbeddedServerConfiguration {
8386

84-
@Bean
85-
@ConditionalOnMissingBean
86-
ReactorResourceFactory reactorResourceFactory() {
87-
return new ReactorResourceFactory();
88-
}
89-
9087
@Bean
9188
@ConditionalOnMissingBean
9289
RSocketServerFactory rSocketServerFactory(RSocketProperties properties, ReactorResourceFactory resourceFactory,

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525
import org.springframework.beans.factory.ObjectProvider;
2626
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2727
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
28+
import org.springframework.boot.autoconfigure.reactor.netty.ReactorNettyConfigurations;
2829
import org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory;
2930
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
3031
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
@@ -39,6 +40,7 @@
3940
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
4041
import org.springframework.context.annotation.Bean;
4142
import org.springframework.context.annotation.Configuration;
43+
import org.springframework.context.annotation.Import;
4244
import org.springframework.http.client.reactive.JettyResourceFactory;
4345
import org.springframework.http.client.reactive.ReactorResourceFactory;
4446

@@ -57,14 +59,9 @@ abstract class ReactiveWebServerFactoryConfiguration {
5759
@Configuration(proxyBeanMethods = false)
5860
@ConditionalOnMissingBean(ReactiveWebServerFactory.class)
5961
@ConditionalOnClass({ HttpServer.class })
62+
@Import(ReactorNettyConfigurations.ReactorResourceFactoryConfiguration.class)
6063
static class EmbeddedNetty {
6164

62-
@Bean
63-
@ConditionalOnMissingBean
64-
ReactorResourceFactory reactorServerResourceFactory() {
65-
return new ReactorResourceFactory();
66-
}
67-
6865
@Bean
6966
NettyReactiveWebServerFactory nettyReactiveWebServerFactory(ReactorResourceFactory resourceFactory,
7067
ObjectProvider<NettyRouteProvider> routes, ObjectProvider<NettyServerCustomizer> serverCustomizers) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorConfiguration.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,10 @@
2424
import org.springframework.beans.factory.ObjectProvider;
2525
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2626
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
27+
import org.springframework.boot.autoconfigure.reactor.netty.ReactorNettyConfigurations;
2728
import org.springframework.context.annotation.Bean;
2829
import org.springframework.context.annotation.Configuration;
30+
import org.springframework.context.annotation.Import;
2931
import org.springframework.context.annotation.Lazy;
3032
import org.springframework.http.client.reactive.ClientHttpConnector;
3133
import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector;
@@ -48,14 +50,9 @@ class ClientHttpConnectorConfiguration {
4850
@Configuration(proxyBeanMethods = false)
4951
@ConditionalOnClass(reactor.netty.http.client.HttpClient.class)
5052
@ConditionalOnMissingBean(ClientHttpConnector.class)
53+
@Import(ReactorNettyConfigurations.ReactorResourceFactoryConfiguration.class)
5154
static class ReactorNetty {
5255

53-
@Bean
54-
@ConditionalOnMissingBean
55-
ReactorResourceFactory reactorClientResourceFactory() {
56-
return new ReactorResourceFactory();
57-
}
58-
5956
@Bean
6057
@Lazy
6158
ReactorClientHttpConnector reactorClientHttpConnector(ReactorResourceFactory reactorResourceFactory,

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorAutoConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ void whenReactorIsAvailableThenReactorBeansAreDefined() {
5656
BeanDefinition connectorDefinition = context.getBeanFactory()
5757
.getBeanDefinition("reactorClientHttpConnector");
5858
assertThat(connectorDefinition.isLazyInit()).isTrue();
59-
assertThat(context).hasBean("reactorClientResourceFactory");
59+
assertThat(context).hasSingleBean(ReactorResourceFactory.class);
6060
});
6161
}
6262

spring-boot-project/spring-boot-devtools/src/main/resources/org/springframework/boot/devtools/env/devtools-property-defaults.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ spring.template.provider.cache=false
1313
spring.thymeleaf.cache=false
1414
spring.web.resources.cache.period=0
1515
spring.web.resources.chain.cache=false
16+
spring.reactor.netty.shutdown-quiet-period=0s

0 commit comments

Comments
 (0)