GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — KQueueSocketChannel with AUTO_READ=false may fire channelInactive before all pending bytes are delivered after EOF · Issue #17290 · netty/netty

KQueueSocketChannel with AUTO_READ=false may fire channelInactive before all pending bytes are delivered after EOF #17290

New issue
Copy link
New issue
Copy link
Closed
Closed
KQueueSocketChannel with AUTO_READ=false may fire channelInactive before all pending bytes are delivered after EOF#17290
Copy link
Milestone
4.1.138.Final

Description

@zhou-hao
zhou-hao
opened on Aug 14, 2026
Issue body actions

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:

  • Fix shutdownInput bug in kqueue for empty recv buffer #16630
  • Fix shutdownInput bug in kqueue for empty recv buffer (#16630) #16638

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.

Activity

  1. adityaanikam commented on Aug 15, 2026

    @adityaanikam
    adityaanikam
    on Aug 15, 2026
    More actions

    Traced the specific mechanism you pointed at, and it doesn't hold up quite the way you described, though the bug itself reproduces exactly as you show. KQueueRecvByteAllocatorHandle does have an EOF override: continueReading() is readEOF || delegate().continueReading(...), so once readEOF is set it returns true unconditionally, autoRead included. That bypass predates both #16630 and #16638, neither PR touched it.

    What I can't rule out, and what looks more likely given the override exists: readEOF() only forces that synchronous re-drain if isActive() is true at the moment EV_EOF/NOTE_RDHUP fires. If EVFILT_READ and the EOF event arrive far enough apart at the kqueue level that isActive() has already flipped false by the time readEOF() runs, the forced re-drain never happens, and whatever's still sitting in the socket buffer gets left behind before channelInactive fires. That's genuinely timing dependent at the OS level though, I don't have a way to confirm it without a macOS box and your reproducer. Worth checking whether isActive() is actually still true when readEOF() runs in a failing case, if you're able to add that logging.

  2. normanmaurer
    added a commit that references this issue on Aug 20, 2026

    Kqueue: Continue reading when EOF is received before notify about cha…

    894159d
  3. normanmaurer commented on Aug 20, 2026

    @normanmaurer
    normanmaurer
    on Aug 20, 2026
    Member
    More actions

    @zhou-hao #17309 ... thanks for the unit test

  4. normanmaurer
    added this to the 4.1.138.Final milestone on Aug 20, 2026
  5. normanmaurer
    added 3 commits that reference this issue on Aug 26, 2026

    Kqueue: Continue reading when EOF is received before notify about cha…

    6d5c366

    Port EOF handling test (#17336)

    6495f11

    Auto-port 5.0: Port EOF handling test (#17337)

    4a8a21b
  6. normanmaurer commented on Aug 28, 2026

    @normanmaurer
    normanmaurer
    on Aug 28, 2026
    Member
    More actions

    This was merged

  7. normanmaurer
    closed this as completedon Aug 28, 2026
  8. lltopk
    added a commit that references this issue on Oct 24, 2026

    Kqueue: Continue reading when EOF is received before notify about cha…

    e718894
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.1.138.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.