[HTTP2] Fix memory leak while writing empty data frame with padding (#11633)

Motivation:

There is a memory leak while writing empty data frame with padding.

The empty data frame was occurred because we are running a proxy server
built by netty, and found that google services always sent data frames
followed by an empty data frame.

Modifications:

Calls the ctx.write even the payload is empty.

Result:

Fix memory leak.

Co-authored-by: Norman Maurer <norman_maurer@apple.com>
This commit is contained in:
Chun-Han, Hsiao 2021-08-31 18:41:49 +08:00 committed by GitHub
parent d2aceea3b0
commit d027ba7320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -219,7 +219,7 @@ public class DefaultHttp2FrameWriter implements Http2FrameWriter, Http2FrameSize
ctx.write(frameHeader2, promiseAggregator.newPromise());
// Write the payload.
if (frameDataBytes != 0 && data != null) { // Make sure Data is not null
if (data != null) { // Make sure Data is not null
if (remainingData == 0) {
ByteBuf lastFrame = data.readSlice(frameDataBytes);
data = null;

View File

@ -160,6 +160,26 @@ public class DefaultHttp2FrameWriterTest {
assertEquals(expectedOutbound, outbound);
}
@Test
public void writeEmptyDataWithPadding() {
int streamId = 1;
ByteBuf payloadByteBuf = Unpooled.buffer();
frameWriter.writeData(ctx, streamId, payloadByteBuf, 2, true, promise);
assertEquals(0, payloadByteBuf.refCnt());
byte[] expectedFrameBytes = {
(byte) 0x00, (byte) 0x00, (byte) 0x02, // payload length
(byte) 0x00, // payload type
(byte) 0x09, // flags
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, // stream id
(byte) 0x01, (byte) 0x00, // padding
};
expectedOutbound = Unpooled.copiedBuffer(expectedFrameBytes);
assertEquals(expectedOutbound, outbound);
}
/**
* Test large headers that exceed {@link DefaultHttp2FrameWriter#maxFrameSize()}
* the remaining headers will be sent in a CONTINUATION frame