Skip to content

Auto-port 4.1: Avoid classloader leak via ImmediateEventExecutor terminationFuture failure - #18359

Merged
normanmaurer merged 1 commit into
4.1from
auto-port-pr-18338-to-4.1
Nov 12, 2026
Merged

normanmaurer merged 1 commit into
4.1from
auto-port-pr-18338-to-4.1

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #18338 to 4.1
Cherry-picked commit: faa14e3


Motivation:

ImmediateEventExecutor.INSTANCE keeps a FailedFuture as its terminationFuture, with an UnsupportedOperationException that is created when the class is initialised. The native backtrace of that exception references the classes of every frame on the stack of whatever code first used ImmediateEventExecutor. When Netty is on the classpath of a servlet container and shared by its web applications, this pins the class loader of the first web application that used it, so that application can't be unloaded after it is undeployed.

This is the same problem as #17128, which #17140 fixed for GlobalEventExecutor only.

Modification:

  • Move StacklessUnsupportedOperationException out of GlobalEventExecutor into a package-private class, and use it for the failure of ImmediateEventExecutor's terminationFuture as well.
  • Add a regression test.

Result:

ImmediateEventExecutor no longer keeps the class loader of its first caller alive. Like #17140, this applies to 4.1 and 5.0 too.

…ailure (#18338)

Motivation:

`ImmediateEventExecutor.INSTANCE` keeps a `FailedFuture` as its
`terminationFuture`, with an `UnsupportedOperationException` that is
created when the class is initialised. The native backtrace of that
exception references the classes of every frame on the stack of whatever
code first used `ImmediateEventExecutor`. When Netty is on the classpath
of a servlet container and shared by its web applications, this pins the
class loader of the first web application that used it, so that
application can't be unloaded after it is undeployed.

This is the same problem as #17128, which #17140 fixed for
`GlobalEventExecutor` only.

Modification:

- Move `StacklessUnsupportedOperationException` out of
`GlobalEventExecutor` into a package-private class, and use it for the
failure of `ImmediateEventExecutor`'s `terminationFuture` as well.
- Add a regression test.

Result:

`ImmediateEventExecutor` no longer keeps the class loader of its first
caller alive. Like #17140, this applies to 4.1 and 5.0 too.

Co-authored-by: Norman Maurer <[email protected]>
(cherry picked from commit faa14e3)
@normanmaurer normanmaurer added this to the 4.1.141.Final milestone Nov 12, 2026
@normanmaurer
normanmaurer merged commit 92a4c6d into 4.1 Nov 12, 2026
18 of 19 checks passed
@normanmaurer
normanmaurer deleted the auto-port-pr-18338-to-4.1 branch November 12, 2026 13:19
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