-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 DoubleByteBuf to send large size messages in TLS mode #447
Conversation
@nkurihar The change looks good. I just have a couple of questions:
|
They are defined as
If TLS is disabled, messages larger than 16384 bytes can be sent at one time.
I added a test code for |
6d0f368
to
2b6d6aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks
## Motivation Keep the data in the direct memory of nio as much as possible to reduce the damage to performance. ## Modifications 1. modify `ByteBuf` directly instead of `MemoryRecords` 2. delay the release timing of `Entry` until after writing to the network channel Co-authored-by: wuzhanpeng <wuzhanpeng@bigo.sg>
…pache#454) Motivation: Remove CompositeBytebuf to avoid on-heap memory copy in `KafkaEntryFormatter#decode` Related to: apache#447 Co-authored-by: wuzhanpeng <wuzhanpeng@bigo.sg> Co-authored-by: Yunze Xu <xyzinfernity@163.com>
Motivation
Issue
When TLS is enabled, messages whose size is larger than 2^14(16384) bytes can not be sent by the following error:
Cause
DoubleByteBuf#readableBytes returns wrong value.
Detail
DoubleByteBuf
has 2 buffers (b1
,b2
) internally.DoubleByteBuf#readableBytes
returnsb1.readableBytes() + b2.readableBytes()
, where readableBytes is defined aswriterIndex
(default: end of the buffer) -readerIndex
(default: 0).However, since
b1.readerIndex
andb2.readerIndex
are not updated through any methods ofDoubleByteBuf
, it always returns the sum of the length ofb1
andb2
.In TLS, messages whose size is larger than 2^14 bytes are divided into several chunks (c.f. 6.2.1. Fragmentation on https://www.ietf.org/rfc/rfc5246.txt).
When sending the second chunk,
DoubleByteBuf#readerIndex
is 16384 whileDoubleByteBuf#readableBytes
returns the length of buffer,IndexOutOfBoundsException
occurs in DoubleByteBuf#nioBuffers which attempts to read the buffer from 16384 to 16384 + length.Modifications
DoubleByteBuf#readableBytes
in order to use AbstractByteBuf#readableBytes insteadTlsProducerConsumerTest
to verify that messages whose size is larger than 2^14 bytes can be sent.AuthenticatedProducerConsumerTest
Note:
In this PR I just deleted
DoubleByteBuf#readableBytes
.Another approach is to update
b1.readerIndex
andb2.readerIndex
whenDoubleByteBuf#readerIndex
is updated, but it seems unnecessary for now.Should we do so?
Result
Messages whose size is larger than 2^14 bytes can be sent when TLS is enabled.