Skip to content

Auto-port 5.0: Reset LengthFieldBasedFrameDecoder state when the frame is shorter than initialBytesToStrip - #17622

Merged
normanmaurer merged 2 commits into
5.0from
auto-port-pr-17606-to-5.0
Sep 25, 2026
Merged

normanmaurer merged 2 commits into
5.0from
auto-port-pr-17606-to-5.0

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #17606 to 5.0
Cherry-picked commit: c784721


Motivation:

When the adjusted frame length is less than initialBytesToStrip, LengthFieldBasedFrameDecoder throws a CorruptedFrameException without resetting frameLengthInt. Every following decode(...) call then skips reading the length field of the next frame, sees the same short frame length again, and throws again. frameLength is 0 in those calls, so no bytes are skipped either. One malformed frame therefore makes every later frame on the connection fail (Adjusted frame length (0) is less than initialBytesToStrip: ...). The same happens on the first malformed frame if its length field and its content arrive in separate reads. All the other error paths of the decoder reset their state and go on with the next frame. This regressed in #12173, which cached the frame length in frameLengthInt but only reset it on the success path.

Modification:

  • Reset frameLengthInt before failing, and skip the frame using frameLengthInt instead of the local frameLength, which is 0 when the length field was read by an earlier call.
  • Add two tests: the malformed frame in one read, and its length field and content in separate reads. Both fail without the change (with the exception above on the following valid frame) and pass with it.

Result:

The decoder fails the malformed frame and then decodes the following frames again. codec-base tests: 352, 0 failures.

This was found by modelling the decoder's frame-length arithmetic and state in Lean 4 (a proof that every error path returns to the "new frame" state failed on this path), then reproducing it with the real class. The change was prepared with Claude Code (Claude Opus 5.5), and the commit has a Co-Authored-By trailer.

🤖 Generated with Claude Code

…an initialBytesToStrip (#17606)

Motivation:

When the adjusted frame length is less than `initialBytesToStrip`,
`LengthFieldBasedFrameDecoder` throws a `CorruptedFrameException`
without resetting `frameLengthInt`. Every following `decode(...)` call
then skips reading the length field of the next frame, sees the same
short frame length again, and throws again. `frameLength` is `0` in
those calls, so no bytes are skipped either. One malformed frame
therefore makes every later frame on the connection fail (`Adjusted
frame length (0) is less than initialBytesToStrip: ...`). The same
happens on the first malformed frame if its length field and its content
arrive in separate reads. All the other error paths of the decoder reset
their state and go on with the next frame. This regressed in #12173,
which cached the frame length in `frameLengthInt` but only reset it on
the success path.

Modification:

- Reset `frameLengthInt` before failing, and skip the frame using
`frameLengthInt` instead of the local `frameLength`, which is `0` when
the length field was read by an earlier call.
- Add two tests: the malformed frame in one read, and its length field
and content in separate reads. Both fail without the change (with the
exception above on the following valid frame) and pass with it.

Result:

The decoder fails the malformed frame and then decodes the following
frames again. `codec-base` tests: 352, 0 failures.

(cherry picked from commit c784721)
@testlens-app

testlens-app Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🚨 TestLens detected 1 failed test 🚨

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-java25-adaptive build > Netty/Common

Test Runs Flakiness
SingleThreadEventExecutorTest > testSuspendDoesNotRaceWithCancelledScheduledTask() ❌ 25% 🔴

🏷️ Commit: 8ea1630
▶️ Tests: 195671 executed
⚪️ Checks: 12/12 completed

Test Failures

SingleThreadEventExecutorTest > testSuspendDoesNotRaceWithCancelledScheduledTask() (Netty/Common in Build PR / linux-x86_64-java25-adaptive build)
org.opentest4j.AssertionFailedError: worker thread did not terminate at iteration 558 ==> expected: <false> but was: <true>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertFalse.failNotFalse(AssertFalse.java:63)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:36)
	at org.junit.jupiter.api.Assertions.assertFalse(Assertions.java:239)
	at io.netty.util.concurrent.SingleThreadEventExecutorTest.testSuspendDoesNotRaceWithCancelledScheduledTask(SingleThreadEventExecutorTest.java:243)
	at java.base/java.lang.reflect.Method.invoke(Method.java:565)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
expected actual
false true

Rerun Controls

Select tests to mute in this pull request:

  • SingleThreadEventExecutorTest > testSuspendDoesNotRaceWithCancelledScheduledTask()

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 2329198 into 5.0 Sep 25, 2026
12 of 13 checks passed
@normanmaurer
normanmaurer deleted the auto-port-pr-17606-to-5.0 branch September 25, 2026 16:47
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Sep 25, 2026
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.

3 participants