Skip to content

Commit 4e38926

Browse files
committed
Improve discovery of (and fix some) netty-releated test buffer leaks
This changeset improves disovery of netty-related buffer leaks if the --warn flag is enabled on the command line when running the gradle tests. Paranoid is enabled all the time now, but the overhead of doing so is very minimal and does not need to be enabled conditionally. --warn is needed since only in that mode stdout is visible on the command line. Running it showed a couple of leaks in tests where two of them are already fixed as part of this commit.
1 parent 13197de commit 4e38926

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

servicetalk-gradle-plugin-internal/src/main/groovy/io/servicetalk/gradle/plugin/internal/ServiceTalkLibraryPlugin.groovy

+5
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ final class ServiceTalkLibraryPlugin extends ServiceTalkCorePlugin {
233233
// Always require native libraries for running tests. This helps to make sure transport-level state machine
234234
// receives all expected network events from Netty.
235235
systemProperty "io.servicetalk.transport.netty.requireNativeLibs", "true"
236+
237+
// Make sure we enable netty leak detection for our tests. By default these are not visible in the logs,
238+
// to see them you must at --warn to your ./gradlew test run in order to see the "showStandardStreams".
239+
systemProperty "io.netty.leakDetection.level", "PARANOID"
240+
systemProperty "io.netty.leakDetection.targetRecords", "25"
236241
}
237242

238243
dependencies {

servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/H2PriorKnowledgeFeatureParityTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ public void channelReadComplete(ChannelHandlerContext ctx) {
20702070
}
20712071

20722072
private static void onDataRead(ChannelHandlerContext ctx, Http2DataFrame data) {
2073-
ctx.write(new DefaultHttp2DataFrame(data.content().retainedDuplicate(), data.isEndStream()));
2073+
ctx.write(new DefaultHttp2DataFrame(data.content(), data.isEndStream()));
20742074
}
20752075

20762076
private void onHeadersRead(ChannelHandlerContext ctx, Http2HeadersFrame headers) {

servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/ServerRespondsOnClosingTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import static org.hamcrest.Matchers.is;
6363

6464
class ServerRespondsOnClosingTest {
65-
6665
private static final HttpResponseFactory RESPONSE_FACTORY = new DefaultHttpResponseFactory(
6766
DefaultHttpHeadersFactory.INSTANCE, DEFAULT_ALLOCATOR, HTTP_1_1);
6867
private static final String RESPONSE_PAYLOAD_BODY = "Hello World";
@@ -252,6 +251,8 @@ private void verifyResponse(String requestPath) {
252251
assertThat("Unexpected response meta-data", metaData.toString(US_ASCII), containsString(requestPath));
253252
ByteBuf payloadBody = channel.readOutbound();
254253
assertThat("Unexpected response payload body", payloadBody.toString(US_ASCII), equalTo(RESPONSE_PAYLOAD_BODY));
254+
metaData.release();
255+
payloadBody.release();
255256
}
256257

257258
private void respondWithFIN() throws Exception {

0 commit comments

Comments
 (0)