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 — Ensure AbstractCoalescingBufferQueue does not end up in inconsistent … by normanmaurer · Pull Request #14220 · netty/netty

Conversation

@normanmaurer

@normanmaurer normanmaurer commented Aug 10, 2024

Copy link
Copy Markdown
Member

…state on error

Motivation:

The code in AbstractCoalescingBufferQueue.remove(...) could lead to inconsistent internal state when for example an exception is thrown because of reference counting problems. Because of this is was possible that while the queue was empty it still showed readableBytes() > 0. This could then lead to various issues internally within netty where we depend on that the queue will eventually returns readableBytes() == 0.

Modifications:

  • Ensure we always decrement readable bytes, even in the cause of an error
  • Also correctly remove the listener if an error happens during handling the buffer.

Result:

Fixes #11959

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

koo-taejin reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@normanmaurer
Ensure AbstractCoalescingBufferQueue does not end up in inconsistent …
8f191ad
…state on error

Motivation:

The code in AbstractCoalescingBufferQueue.remove(...) could lead to inconsistent internal state when for example an exception is thrown because of reference counting problems. Because of this is was possible that while the queue was empty it still showed readableBytes() > 0. This could then lead to various issues internally within netty where we depend on that the queue will eventually returns readableBytes() == 0.

Modifications:

- Ensure we always decrement readable bytes, even in the cause of an error
- Also correctly remove the listener if an error happens during handling the buffer.

Result:

Fixes #11959
@normanmaurer normanmaurer added this to the 4.1.113.Final milestone Aug 10, 2024
@normanmaurer normanmaurer mentioned this pull request Aug 10, 2024
DefaultHttp2RemoteFlowController: writeAllocatedBytes & Endless loop #11959
Closed
@normanmaurer
normanmaurer requested review from bryce-anderson, chrisvest, ejona86 and idelpivnitskiy August 10, 2024 00:57
@normanmaurer
Correctly update state before notify listeners
0464343
chrisvest
chrisvest approved these changes Aug 12, 2024
View reviewed changes

@chrisvest chrisvest left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ejona86
ejona86 approved these changes Aug 13, 2024
View reviewed changes
Comment thread transport/src/main/java/io/netty/channel/AbstractCoalescingBufferQueue.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

idelpivnitskiy
idelpivnitskiy approved these changes Aug 13, 2024
View reviewed changes
@normanmaurer
Simplify by remove type check
d6af198
@normanmaurer
normanmaurer merged commit eaf788e into 4.1 Aug 13, 2024
@normanmaurer
normanmaurer deleted the queue_consistent_state branch August 13, 2024 04:11
normanmaurer added a commit that referenced this pull request Aug 13, 2024
@normanmaurer
Ensure AbstractCoalescingBufferQueue does not end up in inconsistent … (
0f2beb2
#14220)

…state on error

Motivation:

The code in AbstractCoalescingBufferQueue.remove(...) could lead to
inconsistent internal state when for example an exception is thrown
because of reference counting problems. Because of this is was possible
that while the queue was empty it still showed readableBytes() > 0. This
could then lead to various issues internally within netty where we
depend on that the queue will eventually returns readableBytes() == 0.

Modifications:

- Ensure we always decrement readable bytes, even in the cause of an
error
- Also correctly remove the listener if an error happens during handling
the buffer.

Result:

Fixes #11959
normanmaurer added a commit that referenced this pull request Aug 13, 2024
@normanmaurer
Ensure AbstractCoalescingBufferQueue does not end up in inconsistent … (
7f2b3d0
#14220)

…state on error

Motivation:

The code in AbstractCoalescingBufferQueue.remove(...) could lead to
inconsistent internal state when for example an exception is thrown
because of reference counting problems. Because of this is was possible
that while the queue was empty it still showed readableBytes() > 0. This
could then lead to various issues internally within netty where we
depend on that the queue will eventually returns readableBytes() == 0.

Modifications:

- Ensure we always decrement readable bytes, even in the cause of an
error
- Also correctly remove the listener if an error happens during handling
the buffer.

Result:

Fixes #11959
This was referenced Jun 13, 2026
HTTP/2 client OOM: DefaultHttp2RemoteFlowController spins writing empty DATA frames when CoalescingBufferQueue readableBytes desyncs #16946
Closed
Reconcile AbstractCoalescingBufferQueue readableBytes when it drains, and fail stuck HTTP/2 streams instead of spinning empty DATA frames #16947
Merged
normanmaurer added a commit that referenced this pull request Jun 25, 2026
@gavinbunney @normanmaurer
Reconcile AbstractCoalescingBufferQueue readableBytes when it drain…
a5d4f28
…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]>
@netty-project-bot netty-project-bot mentioned this pull request Jun 25, 2026
Auto-port 4.1: Reconcile AbstractCoalescingBufferQueue readableBytes when it drains, and fail stuck HTTP/2 streams instead of spinning empty DATA frames #16997
Merged
normanmaurer added a commit that referenced this pull request Jun 26, 2026
@netty-project-bot @gavinbunney @normanmaurer
Auto-port 4.1: Reconcile AbstractCoalescingBufferQueue readableByte…
26bb273
…s when it drains, and fail stuck HTTP/2 streams instead of spinning empty DATA frames (#16997)

Auto-port of #16947 to 4.1
Cherry-picked commit: a5d4f28

---
**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: Gavin Bunney <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
@chrisvest chrisvest mentioned this pull request Jun 29, 2026
Reconcile AbstractCoalescingBufferQueue readableBytes when it drain… #17018
Merged
chrisvest added a commit that referenced this pull request Jun 30, 2026
@chrisvest @gavinbunney
Reconcile AbstractCoalescingBufferQueue readableBytes when it drain… (
96c78c9
#17018)

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

Co-authored-by: Gavin Bunney <[email protected]>
This was referenced Sep 14, 2026
Http2: Reserve promised stream for PUSH_PROMISE after local RST_STREAM #17471
Closed
cache failure 1233e4a5 #17565
Closed
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@netty-project-bot @gavinbunney
@normanmaurer @lltopk
Auto-port 4.1: Reconcile AbstractCoalescingBufferQueue readableByte…
24e57cf
…s when it drains, and fail stuck HTTP/2 streams instead of spinning empty DATA frames (netty#16997)

Auto-port of netty#16947 to 4.1
Cherry-picked commit: a5d4f28

---
**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: Gavin Bunney <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chrisvest chrisvest chrisvest approved these changes
@ejona86 ejona86 ejona86 approved these changes
@idelpivnitskiy idelpivnitskiy idelpivnitskiy approved these changes
@bryce-anderson bryce-anderson Awaiting requested review from bryce-anderson

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.1.113.Final

Development

Successfully merging this pull request may close these issues.

DefaultHttp2RemoteFlowController: writeAllocatedBytes & Endless loop

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@normanmaurer @chrisvest @ejona86 @idelpivnitskiy
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.