Skip to content

IoUring: fix io_uring datagram writes with non-zero readerIndex (#16905) - #16922

Merged
chrisvest merged 1 commit into
netty:5.0from
chrisvest:5.0-io-uring-udp
Jun 9, 2026
Merged

chrisvest merged 1 commit into
netty:5.0from
chrisvest:5.0-io-uring-udp

Conversation

@chrisvest

Copy link
Copy Markdown
Member

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.

// 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)

…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)
@normanmaurer

Copy link
Copy Markdown
Member

@chrisvest thanks for picking this up.... I had no time yet :/

@chrisvest
chrisvest disabled auto-merge June 9, 2026 00:33
@chrisvest
chrisvest merged commit 726f4db into netty:5.0 Jun 9, 2026
12 of 13 checks passed
@chrisvest
chrisvest deleted the 5.0-io-uring-udp branch June 9, 2026 00:34
@normanmaurer normanmaurer mentioned this pull request Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants