From 51f2e40c6986aed6b533cc4ff0fdacb632c03867 Mon Sep 17 00:00:00 2001 From: Russell You Date: Tue, 23 Aug 2022 08:37:42 +1000 Subject: [PATCH 1/2] Allow Netty default leak detection to be overidden See gh-32144 --- .../autoconfigure/netty/NettyProperties.java | 2 +- ...itional-spring-configuration-metadata.json | 3 +- .../netty/NettyPropertiesTests.java | 42 ------------------- 3 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/netty/NettyPropertiesTests.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/netty/NettyProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/netty/NettyProperties.java index 1f381468a30..06988375eb5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/netty/NettyProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/netty/NettyProperties.java @@ -32,7 +32,7 @@ public class NettyProperties { /** * Level of leak detection for reference-counted buffers. */ - private LeakDetection leakDetection = LeakDetection.SIMPLE; + private LeakDetection leakDetection = null; public LeakDetection getLeakDetection() { return this.leakDetection; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 8ad449554cb..95326fef75d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -1738,7 +1738,8 @@ }, { "name": "spring.netty.leak-detection", - "defaultValue": "simple" + "description": "When null, fall back to Netty system default 'simple' or value of -Dio.netty.leakDetection.level. When set, this will overrride value of -Dio.netty.leakDetection.level", + "defaultValue": "null" }, { "name": "spring.quartz.jdbc.comment-prefix", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/netty/NettyPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/netty/NettyPropertiesTests.java deleted file mode 100644 index df23a8ecb18..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/netty/NettyPropertiesTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.autoconfigure.netty; - -import io.netty.util.ResourceLeakDetector; -import io.netty.util.ResourceLeakDetector.Level; -import org.junit.jupiter.api.Test; - -import org.springframework.test.util.ReflectionTestUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link NettyProperties} - * - * @author Brian Clozel - */ -class NettyPropertiesTests { - - @Test - void defaultValueShouldMatchNettys() { - NettyProperties properties = new NettyProperties(); - ResourceLeakDetector.Level defaultLevel = (Level) ReflectionTestUtils.getField(ResourceLeakDetector.class, - "DEFAULT_LEVEL"); - assertThat(ResourceLeakDetector.Level.valueOf(properties.getLeakDetection().name())).isEqualTo(defaultLevel); - } - -} From 7f2d4fceec77920d63546f9ca7e6dc47dd83eba8 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 23 Aug 2022 07:20:30 +0200 Subject: [PATCH 2/2] Polish "Allow Netty default leak detection to be overidden" See gh-32144 --- .../autoconfigure/netty/NettyProperties.java | 8 ++-- ...itional-spring-configuration-metadata.json | 5 --- .../netty/NettyPropertiesTests.java | 41 +++++++++++++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/netty/NettyPropertiesTests.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/netty/NettyProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/netty/NettyProperties.java index 06988375eb5..de058a102ab 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/netty/NettyProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/netty/NettyProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties; public class NettyProperties { /** - * Level of leak detection for reference-counted buffers. + * Level of leak detection for reference-counted buffers. If not configured via + * 'ResourceLeakDetector.setLevel' or the 'io.netty.leakDetection.level' system + * property, default to 'simple'. */ - private LeakDetection leakDetection = null; + private LeakDetection leakDetection; public LeakDetection getLeakDetection() { return this.leakDetection; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 95326fef75d..83d3ba9a301 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -1736,11 +1736,6 @@ "name": "spring.neo4j.uri", "defaultValue": "bolt://localhost:7687" }, - { - "name": "spring.netty.leak-detection", - "description": "When null, fall back to Netty system default 'simple' or value of -Dio.netty.leakDetection.level. When set, this will overrride value of -Dio.netty.leakDetection.level", - "defaultValue": "null" - }, { "name": "spring.quartz.jdbc.comment-prefix", "defaultValue": [ diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/netty/NettyPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/netty/NettyPropertiesTests.java new file mode 100644 index 00000000000..711eab081e3 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/netty/NettyPropertiesTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.netty; + +import io.netty.util.ResourceLeakDetector; +import io.netty.util.ResourceLeakDetector.Level; +import org.junit.jupiter.api.Test; + +import org.springframework.test.util.ReflectionTestUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link NettyProperties} + * + * @author Brian Clozel + */ +class NettyPropertiesTests { + + @Test + void defaultValueShouldBeConsistent() { + ResourceLeakDetector.Level defaultLevel = (Level) ReflectionTestUtils.getField(ResourceLeakDetector.class, + "DEFAULT_LEVEL"); + assertThat(defaultLevel).isEqualTo(Level.SIMPLE); + } + +}