Skip to content

IoUring: fix TCP Fast Open initial writes with readerIndex and composites (#16929) - #16935

Merged
normanmaurer merged 1 commit into
5.0from
fast_open5
Jun 11, 2026
Merged

normanmaurer merged 1 commit into
5.0from
fast_open5

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:

AbstractIoUringChannel uses sendmsg(MSG_FASTOPEN) for TCP Fast Open
initial data. This path did not handle all ByteBuf layouts correctly.

A CompositeByteBuf written before connect, for example:

  ByteBuf initialData = alloc.compositeDirectBuffer()
          .addComponent(true, directBuffer("[fastopen-"))
          .addComponent(true, directBuffer("composite-"))
          .addComponent(true, directBuffer("data]"));
  channel.write(initialData);
  channel.connect(remote).sync();

fails with:

  Exception in thread "main" java.lang.UnsupportedOperationException
      at io.netty.buffer.CompositeByteBuf.internalNioBuffer(CompositeByteBuf.java:1681)
      at io.netty.channel.uring.IoUring.memoryAddress(IoUring.java:388)

A direct buffer with a non-zero readerIndex also sends from the wrong
offset:

  ByteBuf initialData = alloc.directBuffer();
  initialData.writeBytes("BAD-PREFIX-".getBytes(US_ASCII));
  initialData.writeBytes("EXPECTED-tfo-reader-index".getBytes(US_ASCII));
  initialData.readerIndex("BAD-PREFIX-".length());

expected: EXPECTED-tfo-reader-index
actual: BAD-PREFIX-EXPECTED-tfo-r

Modification:

  • Use the readable region for direct ByteBuf initial data, and use an
    IovArray backed msghdr for buffers without a memory address.

  • Add the new TCP Fast Open cases to the shared socket test suite.

Result:

TCP Fast Open initial writes now work correctly with non-zero
readerIndex and CompositeByteBuf.

…ites (#16929)

Motivation:

`AbstractIoUringChannel` uses `sendmsg(MSG_FASTOPEN)` for TCP Fast Open
initial data. This path did not handle all `ByteBuf` layouts correctly.

A `CompositeByteBuf` written before connect, for example:

```java
  ByteBuf initialData = alloc.compositeDirectBuffer()
          .addComponent(true, directBuffer("[fastopen-"))
          .addComponent(true, directBuffer("composite-"))
          .addComponent(true, directBuffer("data]"));
  channel.write(initialData);
  channel.connect(remote).sync();
```

fails with:

``` java
  Exception in thread "main" java.lang.UnsupportedOperationException
      at io.netty.buffer.CompositeByteBuf.internalNioBuffer(CompositeByteBuf.java:1681)
      at io.netty.channel.uring.IoUring.memoryAddress(IoUring.java:388)
```

A direct buffer with a non-zero readerIndex also sends from the wrong
offset:

``` java
  ByteBuf initialData = alloc.directBuffer();
  initialData.writeBytes("BAD-PREFIX-".getBytes(US_ASCII));
  initialData.writeBytes("EXPECTED-tfo-reader-index".getBytes(US_ASCII));
  initialData.readerIndex("BAD-PREFIX-".length());
```
expected: EXPECTED-tfo-reader-index
actual:   BAD-PREFIX-EXPECTED-tfo-r

 Modification:

- Use the readable region for direct ByteBuf initial data, and use an
IovArray backed msghdr for buffers without a memory address.

- Add the new TCP Fast Open cases to the shared socket test suite.

Result:

TCP Fast Open initial writes now work correctly with non-zero
readerIndex and CompositeByteBuf.
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Jun 11, 2026
@normanmaurer
normanmaurer merged commit 48e1960 into 5.0 Jun 11, 2026
21 of 23 checks passed
@normanmaurer
normanmaurer deleted the fast_open5 branch June 11, 2026 14:06
@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.

2 participants