We should add a property for configuring the level of leak detection with Netty.

This can be done statically, has obviously a performance cost, but is really useful if an application is dealing with DataBuffer instances or extensive customizations on the Netty engine.

This applies to both server and client use cases, and Netty offers an API for that:

ResourceLeakDetector.setLevel(Level.PARANOID);

We could also consider enabling this by default when the devtools are activated.

Comment From: bclozel

There are a few things going on in Framework about DataBuffer resource leaks (issues being fixed, documentation, and more); I believe this issue could help in that area.

The problem is this property translates into a static call that applies to "everything Netty": Reactor Netty client and server, drivers using Netty like Lettuce, etc - unless those libraries are repackaging Netty, like Couchbase and Neo4J).

For us the natural place to put it would be under spring.netty.leak-detection.level. Developers can still call java -Dio.netty.leakDetection.level=advanced or the static class themselves outside of Spring Boot's control. Right now the closest configuration property we've got is spring.reactor.core.stacktrace-mode.enabled (also static call, applies to a whole lot of libraries using reactor).

Comment From: bclozel

Closing as there isn't much demand for this and the JVM argument might still be the best way to achieve that.

Comment From: JamesChenX

@bclozel Is it possible to reopen this ticket? Our project wants to set the level to ADVANCED in the development environment and SIMPLE in the production environment according to the profile in application.yaml. (We have implemented the feature in our own project but I hope Spring can do this for developers)

Comment From: bclozel

@JamesChenX Thanks for the comment, we'll reconsider this. This is indeed a good use case.

@violetagg I'm wondering if this is enough, or if we should make this feature more general. When dealing with memory leak issues with Netty, are there other options to enable? Typically, when working on a memory leak report - what would you ask developers to enable in their applications to collect useful information? Are specific logs enabled?

I'm trying to figure out if changing the Netty flag is enough or if we can do something more here. Thanks!

Comment From: wilkinsona

Should this be assigned to 2.5.x rather than 2.4.x? If is is an enhancement then I don't think it belongs in 2.4.x.

Comment From: bclozel

Yes, wrong milestone indeed!