Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BrotliEncoder bug that does not mark ByteBuf it encodes as read #13497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ private void encode(ByteBuf msg, boolean preferDirect) throws Exception {
//
// A race condition will not arise because one flush call to encoder will result
// in only 1 call at `write(ByteBuffer)`.
brotliEncoderChannel.write(msg.nioBuffer());
ByteBuffer nioBuffer = msg.nioBuffer();
int position = nioBuffer.position();
brotliEncoderChannel.write(nioBuffer);
msg.skipBytes(nioBuffer.position() - position);
brotliEncoderChannel.flush();
} catch (Exception e) {
ReferenceCountUtil.release(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected void testCompression(final ByteBuf data) throws Exception {
final int dataLength = data.readableBytes();
assertTrue(channel.writeOutbound(data.retain()));
assertTrue(channel.finish());
assertEquals(0, data.readableBytes());

ByteBuf decompressed = readDecompressed(dataLength);
assertEquals(data.resetReaderIndex(), decompressed);
Expand All @@ -101,12 +102,14 @@ protected void testCompressionOfBatchedFlow(final ByteBuf data) throws Exception
while (written + length < dataLength) {
ByteBuf in = data.retainedSlice(written, length);
assertTrue(channel.writeOutbound(in));
assertEquals(0, in.readableBytes());
written += length;
length = rand.nextInt(100);
}
ByteBuf in = data.retainedSlice(written, dataLength - written);
assertTrue(channel.writeOutbound(in));
assertTrue(channel.finish());
assertEquals(0, in.readableBytes());

ByteBuf decompressed = readDecompressed(dataLength);
assertEquals(data, decompressed);
Expand Down