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
This commit is contained in:
Norman Maurer 2019-08-14 13:28:16 +02:00 committed by GitHub
parent 1fa7a5e697
commit 1cce3b1ac9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,6 +38,9 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; 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.Http2CodecUtil.*;
import static io.netty.handler.codec.http2.Http2Error.CANCEL; import static io.netty.handler.codec.http2.Http2Error.CANCEL;
import static io.netty.handler.codec.http2.Http2Error.ENHANCE_YOUR_CALM; import static io.netty.handler.codec.http2.Http2Error.ENHANCE_YOUR_CALM;
@ -71,6 +74,8 @@ public class Http2ControlFrameLimitEncoderTest {
private int numWrites; private int numWrites;
private Queue<ChannelPromise> goAwayPromises = new ArrayDeque<ChannelPromise>();
/** /**
* Init fields and do mocking. * Init fields and do mocking.
*/ */
@ -116,7 +121,9 @@ public class Http2ControlFrameLimitEncoderTest {
@Override @Override
public ChannelFuture answer(InvocationOnMock invocationOnMock) { public ChannelFuture answer(InvocationOnMock invocationOnMock) {
ReferenceCountUtil.release(invocationOnMock.getArgument(3)); ReferenceCountUtil.release(invocationOnMock.getArgument(3));
return handlePromise(invocationOnMock, 4); ChannelPromise promise = invocationOnMock.getArgument(4);
goAwayPromises.offer(promise);
return promise;
} }
}); });
Http2Connection connection = new DefaultHttp2Connection(false); Http2Connection connection = new DefaultHttp2Connection(false);
@ -168,6 +175,16 @@ public class Http2ControlFrameLimitEncoderTest {
public void teardown() { public void teardown() {
// Close and release any buffered frames. // Close and release any buffered frames.
encoder.close(); 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 @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() { private ChannelPromise newPromise() {
return new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE); return new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
} }