Skip to content

Replace ClosedChannelException with StacklessClosedChannelException#16506

Merged
normanmaurer merged 2 commits into
netty:4.2from
Munoon:use_stackless_closed_channel_exception_16504
Mar 18, 2026
Merged

Replace ClosedChannelException with StacklessClosedChannelException#16506
normanmaurer merged 2 commits into
netty:4.2from
Munoon:use_stackless_closed_channel_exception_16504

Conversation

@Munoon
Copy link
Copy Markdown
Contributor

@Munoon Munoon commented Mar 17, 2026

Motivation:

SslHandler.channelInactive allocates ClosedChannelException, which collects the stacktrace.
In a high-load environment, with a large number of connections being opened/closed, this introduces GC pressure:
Image

Modification:

Replaced this exception with StacklessClosedChannelException, which will reduce pressure by eliminating the allocation of the StackTraceElement[] array for the stack trace.

Result:

Fixes #16504.

@normanmaurer normanmaurer requested a review from chrisvest March 17, 2026 14:50
@normanmaurer
Copy link
Copy Markdown
Member

This make sense... The only downside is that we now need to expose this as public. Not a big deal tho.

@normanmaurer normanmaurer added this to the 4.2.11.Final milestone Mar 17, 2026
@normanmaurer normanmaurer merged commit 8f744ec into netty:4.2 Mar 18, 2026
19 checks passed
@normanmaurer normanmaurer added the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Mar 18, 2026
@netty-project-bot
Copy link
Copy Markdown
Contributor

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

normanmaurer pushed a commit that referenced this pull request Mar 18, 2026
…n` (#16506)

Motivation:

`SslHandler.channelInactive` allocates `ClosedChannelException`, which
collects the stacktrace.
In a high-load environment, with a large number of connections being
opened/closed, this introduces GC pressure:
<img width="1349" height="315" alt="Image"
src="https://github.com/user-attachments/assets/7d578905-e74c-4fd2-81c6-2af1083ece5b"
/>

Modification:

Replaced this exception with `StacklessClosedChannelException`, which
will reduce pressure by eliminating the allocation of the
`StackTraceElement[]` array for the stack trace.

Result:

Fixes #16504.
normanmaurer pushed a commit that referenced this pull request Mar 18, 2026
…n` (#16506)

Motivation:

`SslHandler.channelInactive` allocates `ClosedChannelException`, which
collects the stacktrace.
In a high-load environment, with a large number of connections being
opened/closed, this introduces GC pressure:
<img width="1349" height="315" alt="Image"
src="https://github.com/user-attachments/assets/7d578905-e74c-4fd2-81c6-2af1083ece5b"
/>

Modification:

Replaced this exception with `StacklessClosedChannelException`, which
will reduce pressure by eliminating the allocation of the
`StackTraceElement[]` array for the stack trace.

Result:

Fixes #16504.
normanmaurer added a commit that referenced this pull request Mar 18, 2026
…n` (#16506) (#16524)

Motivation:

`SslHandler.channelInactive` allocates `ClosedChannelException`, which
collects the stacktrace.
In a high-load environment, with a large number of connections being
opened/closed, this introduces GC pressure:
<img width="1349" height="315" alt="Image"

src="https://github.com/user-attachments/assets/7d578905-e74c-4fd2-81c6-2af1083ece5b"
/>

Modification:

Replaced this exception with `StacklessClosedChannelException`, which
will reduce pressure by eliminating the allocation of the
`StackTraceElement[]` array for the stack trace.

Result:

Fixes #16504.

Co-authored-by: Nikita Ivchenko <munoongg@gmail.com>
@chrisvest chrisvest removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Mar 19, 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.

Proposal: Replace ClosedChannelException with StacklessClosedChannelException

4 participants