In a project with quite a few random tests we see traces of errors of the following type
2023-09-29T07:47:44.44.483+02:00 ERROR 23708 --- [ctor-http-nio-2] io.netty.util.ResourceLeakDetector : LEAK: ByteBuf.release() was not called before being collected. See https://netty.io/wiki/reference-counted-objects.html for more information.
Recent access logs:
spring-projects/spring-boot#1:
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:300).
....
We are using SB 3.1.4 and JVM 17.
We managed to reproduce the case and create a simple test case, for this we call several times a WebTestClient and between each call, we call the GC (I think the Netty leak check needs the GC to remove the reference object to detect the Leak).
Attached is an example to reproduce the problem: https://github.com/rgarciapariente/netty-warns-memoryleak/tree/main
mvn clean verify -Dio.netty.leakDetection.level=PARANOID
The only thing we do in the example (apart from forcing the GC between attempts) is:
@RepeatedTest(10)
void testWebTestClientMemoryLeak() {
testClient.get().uri("/warn").exchange().expectStatus().isOk();
}
If you leave the SIMPLE mode, which is the default mode, it only analyzes 1% of the buffers, so the error is only displayed randomly.
Many thanks & regards
Comment From: rstoyanchev
This is expected since the server returns a body and the test does not consume it. In this case you can add .expectBody(String.class).isEqualTo("ok")
.