Skip to content

Release unsent LastHttpContent in HttpChunkedInput - #17240

Merged
normanmaurer merged 2 commits into
netty:4.2from
Gimini-3:fix-http-chunked-input-last-content-leak
Aug 10, 2026
Merged

normanmaurer merged 2 commits into
netty:4.2from
Gimini-3:fix-http-chunked-input-last-content-leak

Conversation

@Gimini-3

@Gimini-3 Gimini-3 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

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 it is returned from
readChunk. If a ChunkedWriteHandler write is aborted before that point,
closing the input leaves the retained content unreleased.

Modification:

Release the terminating content from close when ownership has not been
transferred, including when the wrapped input close fails. Add coverage for
aborted writes, successful handoff, exceptional close, and repeated close.

Result:

Custom terminating content no longer leaks when an HTTP chunked write is
closed before completion.
@Gimini-3
Gimini-3 marked this pull request as ready for review August 8, 2026 06:31
@normanmaurer

Copy link
Copy Markdown
Member

@normanmaurer normanmaurer added this to the 4.2.18.Final milestone Aug 9, 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 Aug 9, 2026
@Gimini-3

Gimini-3 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

I have now completed and submitted the ICLA. Thanks for the reminder!

@testlens-app

testlens-app Bot commented Aug 10, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: f013054
▶️ Tests: 447955 executed
⚪️ Checks: 18/18 completed


Learn more about TestLens at testlens.app.

@normanmaurer
normanmaurer merged commit 93602ab into netty:4.2 Aug 10, 2026
19 checks passed
@netty-project-bot

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17251

@github-actions github-actions Bot removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Aug 10, 2026
normanmaurer added a commit that referenced this pull request Aug 10, 2026
…7251)

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`

---------

Co-authored-by: Gimin Kim <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Aug 11, 2026
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]>
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
@normanmaurer normanmaurer removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Oct 16, 2026
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