Skip to content

Http2ConnectionHandler: report at most one stream error for a CompositeStreamException - #17470

Merged
normanmaurer merged 4 commits into
4.2from
h2-comp-a6552f04
Sep 22, 2026
Merged

normanmaurer merged 4 commits into
4.2from
h2-comp-a6552f04

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:

RFC 9113, Section 5.4 states that implementations SHOULD report at
most one stream and one connection error as a result of processing a
single condition, even if multiple errors are discovered. When
DefaultHttp2LocalFlowController accumulates per-stream failures (e.g.
while applying a new SETTINGS initial window size) into a single
CompositeStreamException, Http2ConnectionHandler.onError iterated all
contained StreamExceptions and wrote an RST_STREAM for each one,
exceeding the recommended limit of one stream error per result.

Modifications:

  • Http2ConnectionHandler.onError only reports the first StreamException
    contained in a CompositeStreamException instead of iterating and
    reporting every one of them.
  • Add unit tests

Result:

Only one RST_STREAM is written per CompositeStreamException, in line
with the RFC 9113 recommendation.

…teStreamException

Motivation:

RFC 9113, Section 5.4 states that implementations SHOULD report at
most one stream and one connection error as a result of processing a
single condition, even if multiple errors are discovered. When
DefaultHttp2LocalFlowController accumulates per-stream failures (e.g.
while applying a new SETTINGS initial window size) into a single
CompositeStreamException, Http2ConnectionHandler.onError iterated all
contained StreamExceptions and wrote an RST_STREAM for each one,
exceeding the recommended limit of one stream error per result.

Modifications:

- Http2ConnectionHandler.onError only reports the first StreamException
  contained in a CompositeStreamException instead of iterating and
  reporting every one of them.
- Add unit tests

Result:

Only one RST_STREAM is written per CompositeStreamException, in line
with the RFC 9113 recommendation.
@normanmaurer normanmaurer added this to the 4.2.19.Final milestone Sep 14, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Sep 14, 2026
@normanmaurer

Copy link
Copy Markdown
Member Author

I think most peers would also tolerate the old behavior but it's still not correct and wasteful as well..

// and "implementations SHOULD report at most one stream and one connection error as a result".
// Only report the first stream error out of the composite instead of one RST_STREAM per contained
// error, even though multiple streams may be affected by the condition that produced the composite.
Iterator<StreamException> iterator = compositException.iterator();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think for the more general case we have de-dup logic below in the resetStream method: https://github.com/netty/netty/blob/4.2/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ConnectionHandler.java#L835-L838.

Unfortunately it suffers from being to fast and streams are removed from the connection before the next reset occurs. ☹️

…eamException

Motivation:

Bryce Anderson pointed out on PR #17470 that the previous commit's
change to only report the first StreamException contained in a
CompositeStreamException is incorrect for the actual production code
path: DefaultHttp2LocalFlowController's WindowUpdateVisitor builds a
CompositeStreamException while applying a new
SETTINGS_INITIAL_WINDOW_SIZE across all active streams, adding at most
one StreamException per distinct, independently affected stream. If
only the first were reported, the remaining affected streams would be
left open with a corrupted flow-control window instead of being reset.

The RFC 9113, Section 5.4 guidance to report at most one stream error
is about not sending multiple redundant reports for the same
underlying violation; it does not apply across genuinely independent
errors on different streams. That guidance is already satisfied here
since each stream contributes at most one exception to the composite.
The quote attributed to the RFC in the previous commit's comment was
also not an accurate quotation of the spec text.

Modifications:

- Revert Http2ConnectionHandler.onError to reset every stream
  contained in a CompositeStreamException, restoring the pre-#17470
  behavior, and document why that is correct.
- Update the accompanying test to assert that every affected stream is
  reset.

Result:

Each independently affected stream is still correctly reset when a
CompositeStreamException is thrown from flow-control window
processing.
…positeStreamException

Motivation:

Every StreamException currently contained in a CompositeStreamException
belongs to a distinct stream, so resetting each one individually is
correct. However, nothing enforced RFC 9113, Section 5.4's guidance to
report at most one stream error per stream if a composite were ever to
contain more than one StreamException for the same stream id.

Modifications:

- Track which stream ids have already been handled while iterating a
  CompositeStreamException in Http2ConnectionHandler.onError, and skip
  any subsequent StreamException for a stream id that was already
  reported.
- Add a test that verifies only the first StreamException for a given
  stream id results in a RST_STREAM.

Result:

At most one stream error is reported per stream id contained in a
CompositeStreamException.
@testlens-app

testlens-app Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🚨 TestLens detected 2 failed tests 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Build PR / linux-x86_64-java26 build > Netty/Codec/HTTP2

Test Runs Flakiness
Http2MultiplexTransportTest ❌ 1% 🟡

Build PR / macos-x86_64-java11-boringssl build > Netty/Transport/Native/KQueue

Test Runs Flakiness
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithConnect(TestInfo) ❌ 4% 🟡

🏷️ Commit: d20aacc
▶️ Tests: 469566 executed
⚪️ Checks: 26/26 completed

Test Failures

Http2MultiplexTransportTest (Netty/Codec/HTTP2 in Build PR / linux-x86_64-java26 build)
java.lang.IllegalStateException: Possible memory leak detected for resource scope 'Http2MultiplexTransportTest'. Please use paranoid leak detection to get more information, or set -Dio.netty.util.LeakPresenceDetector.trackCreationStack=true
	at io.netty.util.LeakPresenceDetector$ResourceScope.check(LeakPresenceDetector.java:308)
	at io.netty.util.LeakPresenceDetector$ResourceScope.close(LeakPresenceDetector.java:328)
	at io.netty.util.test.LeakPresenceExtension.afterAll(LeakPresenceExtension.java:140)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:511)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1450)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2019)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithConnect(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-x86_64-java11-boringssl build)
org.opentest4j.AssertionFailedError
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendWithConnect0(DatagramUnicastTest.java:430)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendWithConnect(DatagramUnicastTest.java:383)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendWithConnect(DatagramUnicastTest.java:212)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$7.run(DatagramUnicastTest.java:206)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$7.run(DatagramUnicastTest.java:203)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendWithConnect(DatagramUnicastTest.java:203)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

Rerun Controls

Select tests to mute in this pull request:

  • Http2MultiplexTransportTest
  • KQueueDatagramUnicastIPv6MappedTest > testSimpleSendWithConnect(TestInfo)

Reuse successful test results:

  • ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app/docs.

@normanmaurer
normanmaurer merged commit 9676719 into 4.2 Sep 22, 2026
25 of 27 checks passed
@normanmaurer
normanmaurer deleted the h2-comp-a6552f04 branch September 22, 2026 16:58
@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17595

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #17596

@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Sep 22, 2026
normanmaurer added a commit that referenced this pull request Sep 22, 2026
…r for a CompositeStreamException (#17596)

Auto-port of #17470 to 5.0
Cherry-picked commit: 9676719

---
Motivation:

RFC 9113, Section 5.4 states that implementations SHOULD report at
most one stream and one connection error as a result of processing a
single condition, even if multiple errors are discovered. When
DefaultHttp2LocalFlowController accumulates per-stream failures (e.g.
while applying a new SETTINGS initial window size) into a single
CompositeStreamException, Http2ConnectionHandler.onError iterated all
contained StreamExceptions and wrote an RST_STREAM for each one,
exceeding the recommended limit of one stream error per result.

Modifications:

- Http2ConnectionHandler.onError only reports the first StreamException
  contained in a CompositeStreamException instead of iterating and
  reporting every one of them.
- Add unit tests

Result:

Only one RST_STREAM is written per CompositeStreamException, in line
with the RFC 9113 recommendation.

---------

Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Sep 22, 2026
…r for a CompositeStreamException (#17595)

Auto-port of #17470 to 4.1
Cherry-picked commit: 9676719

---
Motivation:

RFC 9113, Section 5.4 states that implementations SHOULD report at
most one stream and one connection error as a result of processing a
single condition, even if multiple errors are discovered. When
DefaultHttp2LocalFlowController accumulates per-stream failures (e.g.
while applying a new SETTINGS initial window size) into a single
CompositeStreamException, Http2ConnectionHandler.onError iterated all
contained StreamExceptions and wrote an RST_STREAM for each one,
exceeding the recommended limit of one stream error per result.

Modifications:

- Http2ConnectionHandler.onError only reports the first StreamException
  contained in a CompositeStreamException instead of iterating and
  reporting every one of them.
- Add unit tests

Result:

Only one RST_STREAM is written per CompositeStreamException, in line
with the RFC 9113 recommendation.

Co-authored-by: Norman Maurer <[email protected]>
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…r for a CompositeStreamException (netty#17595)

Auto-port of netty#17470 to 4.1
Cherry-picked commit: 9676719

---
Motivation:

RFC 9113, Section 5.4 states that implementations SHOULD report at
most one stream and one connection error as a result of processing a
single condition, even if multiple errors are discovered. When
DefaultHttp2LocalFlowController accumulates per-stream failures (e.g.
while applying a new SETTINGS initial window size) into a single
CompositeStreamException, Http2ConnectionHandler.onError iterated all
contained StreamExceptions and wrote an RST_STREAM for each one,
exceeding the recommended limit of one stream error per result.

Modifications:

- Http2ConnectionHandler.onError only reports the first StreamException
  contained in a CompositeStreamException instead of iterating and
  reporting every one of them.
- Add unit tests

Result:

Only one RST_STREAM is written per CompositeStreamException, in line
with the RFC 9113 recommendation.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants