Skip to content

Reconcile AbstractCoalescingBufferQueue readableBytes when it drain… - #17018

Merged
chrisvest merged 1 commit into
netty:5.0from
chrisvest:5.0-queue-spin
Jun 30, 2026
Merged

chrisvest merged 1 commit into
netty:5.0from
chrisvest:5.0-queue-spin

Conversation

@chrisvest

Copy link
Copy Markdown
Member

…s, and fail stuck HTTP/2 streams instead of spinning empty DATA frames (#16947)

Motivation:

On a proxy doing HTTP/2 egress we OOMed when the remote flow controller spun writing empty DATA frames (~134M) into an already-unwritable channel. This is the OOM from #11959, still reachable on 4.2.12.Final despite #14220 - that fix only closed the exception-in-remove route and left two gaps:

  • CoalescingBufferQueue.remove(...) can leave readableBytes > 0 with an empty deque -> it decrements by a buffer's live readable bytes, and its empty-queue early return asserts rather than reconciles
  • Also writeAllocatedBytes re-writes a frame that makes no progress without ever checking channel writability.

Full investigation and heap dump in #16946.

Modification:

  • AbstractCoalescingBufferQueue - add a reconcileReadableBytes() (called at the remove(...) early return and after the drain loop) so an empty queue always reports 0 readable bytes.
  • DefaultHttp2RemoteFlowController.writeAllocatedBytes - if the head frame is given a positive budget but is neither removed nor shrinks across two consecutive iterations, fail the stream via cancel path instead.
  • Tests cover the queue desync, the stuck-frame spin (failing the stream), and a single no-progress pass (tolerated).

Result:

The queue can't report bytes it can't produce, and the flow controller can't emit empty DATA frames unboundedly - a wedged stream fails cleanly instead of OOMing the connection. No public API change.

Fixes #16946


Co-authored-by: Norman Maurer [email protected]

(cherry picked from commit a5d4f28)

…s, and fail stuck HTTP/2 streams instead of spinning empty DATA frames (netty#16947)

**Motivation:**

On a proxy doing HTTP/2 egress we OOMed when the remote flow controller
spun writing empty DATA frames (~134M) into an already-unwritable
channel. This is the OOM from netty#11959, still reachable on `4.2.12.Final`
despite netty#14220 - that fix only closed the exception-in-`remove` route
and left two gaps:

* `CoalescingBufferQueue.remove(...)` can leave `readableBytes > 0` with
an empty deque -> it decrements by a buffer's *live* readable bytes, and
its empty-queue early return asserts rather than reconciles
* Also `writeAllocatedBytes` re-writes a frame that makes no progress
without ever checking channel writability.

Full investigation and heap dump in netty#16946.

**Modification:**

* `AbstractCoalescingBufferQueue` - add a `reconcileReadableBytes()`
(called at the `remove(...)` early return and after the drain loop) so
an empty queue always reports 0 readable bytes.
* `DefaultHttp2RemoteFlowController.writeAllocatedBytes` - if the head
frame is given a positive budget but is neither removed nor shrinks
across two consecutive iterations, fail the stream via cancel path
instead.
* Tests cover the queue desync, the stuck-frame spin (failing the
stream), and a single no-progress pass (tolerated).

**Result:**

The queue can't report bytes it can't produce, and the flow controller
can't emit empty DATA frames unboundedly - a wedged stream fails cleanly
instead of OOMing the connection. No public API change.

Fixes netty#16946

---------

Co-authored-by: Norman Maurer <[email protected]>

(cherry picked from commit a5d4f28)
@chrisvest chrisvest added this to the 5.0.0.Final milestone Jun 29, 2026
@chrisvest
chrisvest enabled auto-merge (squash) June 29, 2026 23:04
@chrisvest
chrisvest merged commit 96c78c9 into netty:5.0 Jun 30, 2026
12 of 13 checks passed
@chrisvest
chrisvest deleted the 5.0-queue-spin branch June 30, 2026 17:13
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