Expected behavior
When the peer writes and flushes the complete payload and then shuts down its output, a KQueueSocketChannel configured with AUTO_READ=false should deliver all pending inbound bytes before firing channelInactive, as long as the application continues calling read().
Temporarily pausing reads should not cause already-sent bytes to be lost.
Actual behavior
On macOS kqueue, the client may fire channelInactive before all bytes written by the server are delivered to the pipeline.
The standalone reproducer uses:
- a loopback JDK TCP server
- a deterministic 32 MiB payload
AUTO_READ=false
FixedRecvByteBufAllocator(8192)
- one explicit read request at a time
- a single 750 ms pause after receiving 128 KiB
- byte-count and SHA-256 verification
Example kqueue result with Netty 4.1.137.Final:
transport=kqueue
channel=io.netty.channel.kqueue.KQueueSocketChannel
payload=33,554,432 bytes
server sent=33,554,432 bytes
client received=32,284,672 bytes
sha256Match=false
terminal=channelInactive
RESULT: REPRODUCED
The same test using NIO receives the complete payload:
transport=nio
channel=io.netty.channel.socket.nio.NioSocketChannel
payload=33,554,432 bytes
server sent=33,554,432 bytes
client received=33,554,432 bytes
sha256Match=true
terminal=channelInactive
RESULT: PASS
The behavior is timing-sensitive. In one fresh 4.1.137.Final verification, the first kqueue run passed, followed by 10/10 reproductions.
The issue was also reproduced with:
| Netty version |
Result |
4.1.135.Final |
Reproduced in 5/5 runs |
4.1.136.Final |
Reproduced |
4.1.137.Final |
Reproduced |
This does not appear to have been introduced specifically in 4.1.137.Final.
The original application-level symptom was Reactor Netty PrematureCloseException: Connection prematurely closed DURING response, but the reproducer removes HTTP, Reactor, proxies, and application code. The equivalent direct Netty symptom is incomplete delivery followed by channelInactive.
Steps to reproduce
git clone https://github.com/zhou-hao/netty-kqueue-eof-reproducer.git
cd netty-kqueue-eof-reproducer
mvn -q compile exec:java \
-Dexec.args="--transport=kqueue --scenario=exact"
Because the behavior is timing-sensitive, repeat the command if the first run passes:
for i in $(seq 1 10); do
mvn -q compile exec:java \
-Dexec.args="--transport=kqueue --scenario=exact"
done
Run the NIO control:
mvn -q compile exec:java \
-Dexec.args="--transport=nio --scenario=exact"
Run the intentionally truncated control:
mvn -q compile exec:java \
-Dexec.args="--transport=kqueue --scenario=truncated"
The truncated scenario must print RESULT: EXPECTED_FAILURE, proving that the byte-count and digest checks reject a genuinely short response.
Minimal yet complete reproducer code (or URL to code)
https://github.com/zhou-hao/netty-kqueue-eof-reproducer
Relevant commit:
zhou-hao/netty-kqueue-eof-reproducer@1f3165e
Netty version
Reproduced with:
4.1.135.Final
4.1.136.Final
4.1.137.Final
Both netty-all and netty-transport-native-kqueue use the same version.
JVM version (e.g. java -version)
openjdk version "21.0.10" 2026-01-20 LTS
OpenJDK Runtime Environment Temurin-21.0.10+7
OpenJDK 64-Bit Server VM Temurin-21.0.10+7
The issue was also initially observed with JDK 17.
OS version (e.g. uname -a)
Darwin 25.5.0
Darwin Kernel Version 25.5.0
arm64
macOS 26.5.2, Apple Silicon.
Additional notes
This may be related to the kqueue EOF/input-shutdown path changed by:
Those changes touch AbstractKQueueStreamChannel.readReady(...) and KQueueRecvByteAllocatorHandle.
The description of #16630 mentions that allocHandle.continueReading() is guaranteed to remain true after EOF so that the receive buffer is drained. In the 4.1 implementation, however, the delegated DefaultMaxMessagesRecvByteBufAllocator.MaxMessageHandle.continueReading(...) requires config.isAutoRead() to be true.
With AUTO_READ=false, it therefore appears possible for the current read loop to stop before all pending bytes are delivered.
Since 4.1.135.Final also reproduces the issue, I am not claiming that #16638 introduced the behavior. The PRs are referenced because they modify the same EOF/read-drain path.