From 3110c801754056c0ca6afd56169be9b2398ed954 Mon Sep 17 00:00:00 2001 From: Sean Yang Date: Fri, 27 Sep 2024 10:49:54 +0000 Subject: [PATCH] Does not override defaults max stream size --- .../apache/dubbo/config/nested/ServletConfig.java | 3 ++- .../autoconfigure/DubboTriple3AutoConfiguration.java | 12 +++++++----- .../autoconfigure/DubboTripleAutoConfiguration.java | 12 +++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ServletConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ServletConfig.java index 4de93cbfdba..1c3f84020d7 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ServletConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ServletConfig.java @@ -31,7 +31,8 @@ public class ServletConfig implements Serializable { /** * Maximum concurrent streams. *

For HTTP/2 - *

The default value is {@link Integer#MAX_VALUE}. + *

Note that the default value for tomcat is 20. Highly recommended to change it to {@link Integer#MAX_VALUE} + *

If set to a negative number, the actual value will be set to {@link Integer#MAX_VALUE}. */ private Integer maxConcurrentStreams; diff --git a/dubbo-spring-boot/dubbo-spring-boot-3-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboTriple3AutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-3-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboTriple3AutoConfiguration.java index 52db14fe466..8caac7a29a7 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-3-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboTriple3AutoConfiguration.java +++ b/dubbo-spring-boot/dubbo-spring-boot-3-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboTriple3AutoConfiguration.java @@ -44,7 +44,7 @@ public class DubboTriple3AutoConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnClass(Filter.class) @ConditionalOnWebApplication(type = Type.SERVLET) - @ConditionalOnProperty(prefix = PREFIX, name = "enabled") + @ConditionalOnProperty(prefix = PREFIX, name = "enabled", havingValue = "true") public static class TripleServletConfiguration { @Bean @@ -62,15 +62,17 @@ public FilterRegistrationBean tripleProtocolFilter( @Bean @ConditionalOnClass(Http2Protocol.class) - WebServerFactoryCustomizer tripleTomcatHttp2Customizer( - @Value("${" + PREFIX + ".max-concurrent-streams:2147483647}") int maxConcurrentStreams) { + @ConditionalOnProperty(prefix = PREFIX, name = "max-concurrent-streams") + public WebServerFactoryCustomizer tripleTomcatHttp2Customizer( + @Value("${" + PREFIX + ".max-concurrent-streams}") int maxConcurrentStreams) { return factory -> factory.addConnectorCustomizers(connector -> { ProtocolHandler handler = connector.getProtocolHandler(); for (UpgradeProtocol upgradeProtocol : handler.findUpgradeProtocols()) { if (upgradeProtocol instanceof Http2Protocol) { Http2Protocol protocol = (Http2Protocol) upgradeProtocol; - protocol.setMaxConcurrentStreams(maxConcurrentStreams); - protocol.setMaxConcurrentStreamExecution(maxConcurrentStreams); + int value = maxConcurrentStreams <= 0 ? Integer.MAX_VALUE : maxConcurrentStreams; + protocol.setMaxConcurrentStreams(value); + protocol.setMaxConcurrentStreamExecution(value); } } }); diff --git a/dubbo-spring-boot/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboTripleAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboTripleAutoConfiguration.java index 06ad57da535..3dfecdb9529 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboTripleAutoConfiguration.java +++ b/dubbo-spring-boot/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboTripleAutoConfiguration.java @@ -45,7 +45,7 @@ public class DubboTripleAutoConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnClass(Filter.class) @ConditionalOnWebApplication(type = Type.SERVLET) - @ConditionalOnProperty(prefix = PREFIX, name = "enabled") + @ConditionalOnProperty(prefix = PREFIX, name = "enabled", havingValue = "true") public static class TripleServletConfiguration { @Bean @@ -63,15 +63,17 @@ public FilterRegistrationBean tripleProtocolFilter( @Bean @ConditionalOnClass(Http2Protocol.class) - WebServerFactoryCustomizer tripleTomcatHttp2Customizer( - @Value("${" + PREFIX + ".max-concurrent-streams:2147483647}") int maxConcurrentStreams) { + @ConditionalOnProperty(prefix = PREFIX, name = "max-concurrent-streams") + public WebServerFactoryCustomizer tripleTomcatHttp2Customizer( + @Value("${" + PREFIX + ".max-concurrent-streams}") int maxConcurrentStreams) { return factory -> factory.addConnectorCustomizers(connector -> { ProtocolHandler handler = connector.getProtocolHandler(); for (UpgradeProtocol upgradeProtocol : handler.findUpgradeProtocols()) { if (upgradeProtocol instanceof Http2Protocol) { Http2Protocol protocol = (Http2Protocol) upgradeProtocol; - protocol.setMaxConcurrentStreams(maxConcurrentStreams); - protocol.setMaxConcurrentStreamExecution(maxConcurrentStreams); + int value = maxConcurrentStreams <= 0 ? Integer.MAX_VALUE : maxConcurrentStreams; + protocol.setMaxConcurrentStreams(value); + protocol.setMaxConcurrentStreamExecution(value); } } });