From 1cce3b1ac9293940a1731ea31455d538631b6329 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 14 Aug 2019 13:28:16 +0200 Subject: [PATCH] Fix ByteBuf leak in Http2ControlFrameLimitEncoderTest (#9466) Motivation: We recently introduced Http2ControlFrameLimitEncoderTest which did not correctly notify the goAway promises and so leaked buffers. Modifications: Correctly notify all promises and so release the debug data. Result: Fixes leak in HTTP2 test --- .../Http2ControlFrameLimitEncoderTest.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ControlFrameLimitEncoderTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ControlFrameLimitEncoderTest.java index b8144665bd..bbae3af5ae 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ControlFrameLimitEncoderTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ControlFrameLimitEncoderTest.java @@ -38,6 +38,9 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.util.ArrayDeque; +import java.util.Queue; + import static io.netty.handler.codec.http2.Http2CodecUtil.*; import static io.netty.handler.codec.http2.Http2Error.CANCEL; import static io.netty.handler.codec.http2.Http2Error.ENHANCE_YOUR_CALM; @@ -71,6 +74,8 @@ public class Http2ControlFrameLimitEncoderTest { private int numWrites; + private Queue goAwayPromises = new ArrayDeque(); + /** * Init fields and do mocking. */ @@ -116,7 +121,9 @@ public class Http2ControlFrameLimitEncoderTest { @Override public ChannelFuture answer(InvocationOnMock invocationOnMock) { ReferenceCountUtil.release(invocationOnMock.getArgument(3)); - return handlePromise(invocationOnMock, 4); + ChannelPromise promise = invocationOnMock.getArgument(4); + goAwayPromises.offer(promise); + return promise; } }); Http2Connection connection = new DefaultHttp2Connection(false); @@ -168,6 +175,16 @@ public class Http2ControlFrameLimitEncoderTest { public void teardown() { // Close and release any buffered frames. encoder.close(); + + // Notify all goAway ChannelPromise instances now as these will also release the retained ByteBuf for the + // debugData. + for (;;) { + ChannelPromise promise = goAwayPromises.poll(); + if (promise == null) { + break; + } + promise.setSuccess(); + } } @Test @@ -254,12 +271,6 @@ public class Http2ControlFrameLimitEncoderTest { } } - private static void assertWriteFailure(ChannelFuture future) { - Http2Exception exception = (Http2Exception) future.cause(); - assertEquals(ShutdownHint.HARD_SHUTDOWN, exception.shutdownHint()); - assertEquals(Http2Error.ENHANCE_YOUR_CALM, exception.error()); - } - private ChannelPromise newPromise() { return new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE); }