Repository navigation
IoUring: fix io_uring datagram writes with non-zero readerIndex (#16905) - #16922
Merged
Merged
Conversation
…y#16905) Motivation: `IoUringDatagramChannel` currently builds the send buffer address from the ByteBuf base memory address. When a direct ByteBuf has a non-zero `readerIndex`, UDP writes may send bytes from the beginning of the buffer instead of the readable region. ``` java // skip eventloopGroup and server/client channel initialization byte[] BAD_PREFIX = "BAD-PREFIX-".getBytes(StandardCharsets.UTF_8); byte[] EXPECTED = "EXPECTED-direct-reader-index".getBytes(StandardCharsets.UTF_8); InetSocketAddress recipient = (InetSocketAddress) server.localAddress(); ByteBuf content = client.alloc().directBuffer(BAD_PREFIX.length + EXPECTED.length); content.writeBytes(BAD_PREFIX); content.writeBytes(EXPECTED); content.readerIndex(BAD_PREFIX.length); client.writeAndFlush(new DatagramPacket(content, recipient)).sync(); byte[] actual = received.join(); System.out.println(new String(actual)); ``` this code prints `BAD-PREFIX-EXPECTED-direct-r`, but it should print `EXPECTED-direct-reader-index` Modification: Add the ByteBuf readerIndex() to the memory address used for io_uringdatagram sendmsg writes Result: Datagram writes now use the readable region of direct ByteBufs correctly, including buffers with a non-zero readerIndex. --------- Co-authored-by: Norman Maurer <[email protected]> (cherry picked from commit 38ccefc)
Member
|
@chrisvest thanks for picking this up.... I had no time yet :/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
IoUringDatagramChannelcurrently builds the send buffer address from the ByteBuf base memory address. When a direct ByteBuf has a non-zeroreaderIndex, UDP writes may send bytes from the beginning of the buffer instead of the readable region.this code prints
BAD-PREFIX-EXPECTED-direct-r, but it should printEXPECTED-direct-reader-indexModification:
Add the ByteBuf readerIndex() to the memory address used for io_uringdatagram sendmsg writes
Result:
Datagram writes now use the readable region of direct ByteBufs correctly, including buffers with a non-zero readerIndex.
Co-authored-by: Norman Maurer [email protected]
(cherry picked from commit 38ccefc)