Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netty 'spring.netty-leak-detection' default property value is always applied to ResourceLeakDetector #32107

Closed
russellyou opened this issue Aug 18, 2022 · 7 comments
Labels
status: ideal-for-contribution An issue that a contributor can help us with status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@russellyou
Copy link
Contributor

russellyou commented Aug 18, 2022

Spring will override the Netty leak detection level set using -Dio.netty.leakDetection.level=advanced

The code below want to set leak detection if property was not null. But the property has default value as SIMPLE. This will get leak detection overridden as SIMPLE always if you set it other value like 'advanced' outside of Spring

public class NettyProperties {
	private LeakDetection leakDetection = LeakDetection.SIMPLE;

...
public class NettyAutoConfiguration {
	public NettyAutoConfiguration(NettyProperties properties) {
		if (properties.getLeakDetection() != null) {
			NettyProperties.LeakDetection leakDetection = properties.getLeakDetection();
			ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.valueOf(leakDetection.name()));
		}
	}
}
...

changed to

if (properties.getLeakDetection() != LeakDetection.SIMPLE) {

will solve the problem as LeakDetection will be simple if not set.

Happy to raise a PR if this is

Version: current main branch

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 18, 2022
@philwebb
Copy link
Member

This looks like a bug to me, but I think we should probably change the default value in NettyProperties.leakDetection to null rather than updating the NettyAutoConfiguration.

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 18, 2022
@philwebb philwebb added this to the 2.6.x milestone Aug 18, 2022
@philwebb philwebb changed the title Netty leak detection set using -Dio.netty.leakDetection.level incorrectly overridden to LeakDetection.SIMPLE Netty 'spring.netty-leak-detection' default property value is always applied to ResourceLeakDetector Aug 18, 2022
@snicoll
Copy link
Member

snicoll commented Aug 19, 2022

I don't think I agree with that. There are many configuration properties that have a default value that can be overridden by a system property (all our own properties, for a start). I think we should be documenting what the default value is if we decide to offer support for that. See #14338

@bclozel
Copy link
Member

bclozel commented Aug 19, 2022

I think we discussed the null value and decided against that in #26958 (comment)

@philwebb philwebb added the for: team-meeting An issue we'd like to discuss as a team to make progress label Aug 19, 2022
@philwebb
Copy link
Member

We'll have to discuss this one a bit more. We need to decide if -Dio.netty.leakDetection.level=advanced should override our property or not and if that should be always or just when the property has not been defined.

IMO it's a bit strange at the moment that running an app with -Dio.netty.leakDetection.level=advanced and an empty application.properties gets simple leak detection.

@bclozel
Copy link
Member

bclozel commented Aug 19, 2022

I think I've changed my mind. Developers can configure this with:

  • a static call ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
  • -Dio.netty.leakDetection.level=paranoid
  • the Spring Boot configuration property

The configuration property should only apply if a specific value has been set, so setting the default value to null might be a good compromise. With all 3 ways involved, we're always going to find a combination that leads to strange results. This is why we initially declined #14338.

Even with this solution, if ResourceLeakDetector.setLevel() is called within a bean, the configuration property will be overridden. This could be a breaking change if our configuration property currently shadows an existing system property - upgrading Spring Boot might change the resulting behavior.

@philwebb
Copy link
Member

We're going to change the default value in NettyProperties to null and update the description to indicate that when not set the Netty default (which is SIMPLE) will be used.

@philwebb philwebb added status: ideal-for-contribution An issue that a contributor can help us with and removed for: team-meeting An issue we'd like to discuss as a team to make progress labels Aug 22, 2022
@snicoll
Copy link
Member

snicoll commented Aug 23, 2022

closing in favor of PR #32144

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2022
@snicoll snicoll removed this from the 2.6.x milestone Aug 23, 2022
@snicoll snicoll added the status: superseded An issue that has been superseded by another label Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
5 participants