GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Don't leak FixedChannelPool slots on unrelated IllegalArgumentException by allthingssecurity · Pull Request #17609 · netty/netty

Don't leak FixedChannelPool slots on unrelated IllegalArgumentException #17609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
normanmaurer merged 1 commit into netty:4.2 from allthingssecurity:fix-fixedchannelpool-iae-slot-leak
Sep 29, 2026
+58 −4
Merged

Don't leak FixedChannelPool slots on unrelated IllegalArgumentException #17609

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
6f2db9e
Don't leak FixedChannelPool slots on unrelated IllegalArgumentException
allthingssecurity Sep 24, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Don't leak FixedChannelPool slots on unrelated IllegalArgumentException
Motivation:

FixedChannelPool.release(...) does not give back the acquired slot if
the release failed with an IllegalArgumentException, as this is what
SimpleChannelPool uses when the Channel was not acquired from the
pool. However the release also fails with any exception thrown by user
code, for example ChannelPoolHandler.channelReleased(),
ChannelHealthChecker.isHealthy() or an overridden offerChannel(). If
that exception is an IllegalArgumentException, the Channel is closed
but still counted as acquired. The slot is lost forever, and with
maxConnections = 1 every later acquire() waits forever or times out.

Modification:

- Fail the release of a Channel that was not acquired from the pool
  with a package-private ChannelNotAcquiredFromPoolException. It
  extends IllegalArgumentException and keeps the message, so code that
  catches IllegalArgumentException still works.
- Only skip the decrement in FixedChannelPool for that exception.
- Add a test where channelReleased() throws an
  IllegalArgumentException.
- Check in testReleaseDifferentPool that releasing a Channel to the
  wrong pool does not give back a slot of that pool.

Result:

A release that fails for any other reason than "not acquired from this
pool" always gives back its slot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@allthingssecurity @claude
allthingssecurity and claude committed Sep 24, 2026
commit 6f2db9e4d77ec0471775e212498c4972b2e3d256

There are no files selected for viewing

4 changes: 3 additions & 1 deletion 4 transport/src/main/java/io/netty/channel/pool/FixedChannelPool.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ public Future<Void> release(final Channel channel, final Promise<Void> promise)
} else {
Throwable cause = future.cause();
// Check if the exception was not because of we passed the Channel to the wrong pool.
if (!(cause instanceof IllegalArgumentException)) {
// Other failures (for example an IllegalArgumentException thrown by the ChannelPoolHandler)
// must still give back the slot.
if (!(cause instanceof ChannelNotAcquiredFromPoolException)) {
decrementAndRunTaskQueue();
}
promise.setFailure(future.cause());
Expand Down
17 changes: 15 additions & 2 deletions 17 transport/src/main/java/io/netty/channel/pool/SimpleChannelPool.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ private void doReleaseChannel(Channel channel, Promise<Void> promise) {
if (channel.attr(POOL_KEY).getAndSet(null) != this) {
closeAndFail(channel,
// Better include a stacktrace here as this is an user error.
new IllegalArgumentException(
"Channel " + channel + " was not acquired from this ChannelPool"),
new ChannelNotAcquiredFromPoolException(channel),
promise);
} else {
if (releaseHealthCheck) {
Expand Down Expand Up @@ -414,6 +413,20 @@ public Void call() throws Exception {
});
}

/**
* Fails the release of a {@link Channel} that was not acquired from this pool. This lets {@link FixedChannelPool}
* tell it apart from other release failures, which may also be {@link IllegalArgumentException}s thrown by user
* code.
*/
static final class ChannelNotAcquiredFromPoolException extends IllegalArgumentException {

private static final long serialVersionUID = -7390314262213853178L;

ChannelNotAcquiredFromPoolException(Channel channel) {
super("Channel " + channel + " was not acquired from this ChannelPool");
}
}

private static final class ChannelPoolFullException extends IllegalStateException {

private ChannelPoolFullException() {
Expand Down
41 changes: 40 additions & 1 deletion 41 transport/src/test/java/io/netty/channel/pool/FixedChannelPoolTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public void testReleaseDifferentPool() throws Exception {
Channel sc = t.sb.bind(t.address).syncUninterruptibly().channel();
ChannelPoolHandler handler = new TestChannelPoolHandler();
ChannelPool pool = new FixedChannelPool(t.cb, handler, 1, 1);
final ChannelPool pool2 = new FixedChannelPool(t.cb, handler, 1, 1);
final FixedChannelPool pool2 = new FixedChannelPool(t.cb, handler, 1, 1);

final Channel channel = pool.acquire().syncUninterruptibly().getNow();

Expand All @@ -339,6 +339,8 @@ public void execute() throws Throwable {
pool2.release(channel).syncUninterruptibly();
}
});
// Nothing was acquired from pool2, so the failed release must not give back a slot there.
assertEquals(0, pool2.acquiredChannelCount());
sc.close().syncUninterruptibly();
channel.close().syncUninterruptibly();
pool.close();
Expand Down Expand Up @@ -391,6 +393,43 @@ public void testReleaseClosed() {
pool.close();
}

@Test
public void testReleaseFailsWithIllegalArgumentExceptionFromHandler() throws Exception {
Tuple t = bootstrap();

// Start server
Channel sc = t.sb.bind(t.address).syncUninterruptibly().channel();
final IllegalArgumentException exception = new IllegalArgumentException();
FixedChannelPool pool = new FixedChannelPool(t.cb, new AbstractChannelPoolHandler() {
@Override
public void channelCreated(Channel ch) {
// NOOP
}

@Override
public void channelReleased(Channel ch) {
throw exception;
}
}, 1);

Channel channel = pool.acquire().syncUninterruptibly().getNow();
assertEquals(1, pool.acquiredChannelCount());

Future<Void> releaseFuture = pool.release(channel).awaitUninterruptibly();
assertSame(exception, releaseFuture.cause());
// The exception was not caused by releasing the Channel to the wrong pool, so the slot must be given back.
assertEquals(0, pool.acquiredChannelCount());

Future<Channel> acquireFuture = pool.acquire();
assertTrue(acquireFuture.await(1, TimeUnit.SECONDS));
assertTrue(acquireFuture.isSuccess());
assertEquals(1, pool.acquiredChannelCount());

sc.close().syncUninterruptibly();
acquireFuture.getNow().close().syncUninterruptibly();
pool.close();
}

@Test
public void testCloseAsync() throws ExecutionException, InterruptedException {
Tuple t = bootstrap();
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.