Skip to content

Auto-port 4.1: Release unsent LastHttpContent in HttpChunkedInput - #17251

Merged
normanmaurer merged 2 commits into
4.1from
auto-port-pr-17240-to-4.1
Aug 10, 2026
Merged

normanmaurer merged 2 commits into
4.1from
auto-port-pr-17240-to-4.1

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #17240 to 4.1
Cherry-picked commit: 93602ab


Motivation:

HttpChunkedInput retains a custom LastHttpContent until readChunk(...)
returns it. If ChunkedWriteHandler discards a suspended or otherwise
incomplete write, it closes the HttpChunkedInput, but the previous
implementation only closed the wrapped input. The unsent terminating content
therefore remained at refCnt == 1.

Modification:

  • Release the terminating content from HttpChunkedInput.close() when it has
    not been handed off by readChunk(...).
  • Perform that release in a finally block so a wrapped input close failure
    cannot leak the content.
  • Mark the terminal state before releasing so repeated close() calls cannot
    double-release it.
  • Document ownership of a custom terminating content.
  • Add tests for an aborted ChunkedWriteHandler write, the successful handoff
    path, a wrapped input close failure, and repeated close calls.

Result:

Custom terminating content is released when a chunked HTTP write is closed
before completion, while successfully handed-off content remains owned by the
outbound pipeline.

Testing:

  • ./mvnw -q -pl codec-http -Dtest=HttpChunkedInputTest test
  • ./mvnw -q -Pleak -pl codec-http -Dtest=HttpChunkedInputTest test
  • ./mvnw -q -pl codec-http -am -DskipTests install

Motivation:

`HttpChunkedInput` retains a custom `LastHttpContent` until
`readChunk(...)`
returns it. If `ChunkedWriteHandler` discards a suspended or otherwise
incomplete write, it closes the `HttpChunkedInput`, but the previous
implementation only closed the wrapped input. The unsent terminating
content
therefore remained at `refCnt == 1`.

Modification:

- Release the terminating content from `HttpChunkedInput.close()` when
it has
  not been handed off by `readChunk(...)`.
- Perform that release in a `finally` block so a wrapped input close
failure
  cannot leak the content.
- Mark the terminal state before releasing so repeated `close()` calls
cannot
  double-release it.
- Document ownership of a custom terminating content.
- Add tests for an aborted `ChunkedWriteHandler` write, the successful
handoff
  path, a wrapped input close failure, and repeated close calls.

Result:

Custom terminating content is released when a chunked HTTP write is
closed
before completion, while successfully handed-off content remains owned
by the
outbound pipeline.

Testing:

- `./mvnw -q -pl codec-http -Dtest=HttpChunkedInputTest test`
- `./mvnw -q -Pleak -pl codec-http -Dtest=HttpChunkedInputTest test`
- `./mvnw -q -pl codec-http -am -DskipTests install`

(cherry picked from commit 93602ab)
@normanmaurer normanmaurer added this to the 4.1.138.Final milestone Aug 10, 2026
@testlens-app

testlens-app Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: dc54ade
▶️ Tests: 345349 executed
⚪️ Checks: 18/18 completed


Learn more about TestLens at testlens.app.

@normanmaurer
normanmaurer merged commit 9fc0f2a into 4.1 Aug 10, 2026
18 of 19 checks passed
@normanmaurer
normanmaurer deleted the auto-port-pr-17240-to-4.1 branch August 10, 2026 13:06
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…tty#17251)

Auto-port of netty#17240 to 4.1
Cherry-picked commit: 93602ab

---
Motivation:

`HttpChunkedInput` retains a custom `LastHttpContent` until
`readChunk(...)`
returns it. If `ChunkedWriteHandler` discards a suspended or otherwise
incomplete write, it closes the `HttpChunkedInput`, but the previous
implementation only closed the wrapped input. The unsent terminating
content
therefore remained at `refCnt == 1`.

Modification:

- Release the terminating content from `HttpChunkedInput.close()` when
it has
  not been handed off by `readChunk(...)`.
- Perform that release in a `finally` block so a wrapped input close
failure
  cannot leak the content.
- Mark the terminal state before releasing so repeated `close()` calls
cannot
  double-release it.
- Document ownership of a custom terminating content.
- Add tests for an aborted `ChunkedWriteHandler` write, the successful
handoff
  path, a wrapped input close failure, and repeated close calls.

Result:

Custom terminating content is released when a chunked HTTP write is
closed
before completion, while successfully handed-off content remains owned
by the
outbound pipeline.

Testing:

- `./mvnw -q -pl codec-http -Dtest=HttpChunkedInputTest test`
- `./mvnw -q -Pleak -pl codec-http -Dtest=HttpChunkedInputTest test`
- `./mvnw -q -pl codec-http -am -DskipTests install`

---------

Co-authored-by: Gimin Kim <[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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants