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 — pipeline5 by normanmaurer · Pull Request #17671 · netty/netty

pipeline5 #17671

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

Closed
normanmaurer wants to merge 2 commits into 5.0 from pipeline5

Uh oh!

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

Closed

pipeline5 #17671

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
eb25c1b
Don't leak FixedChannelPool slots on unrelated IllegalArgumentExcepti…
allthingssecurity Sep 29, 2026
b7f8b13
Port: Don't corrupt the pipeline when a handler context is removed tw…
allthingssecurity Sep 29, 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
Next Next commit
Don't leak FixedChannelPool slots on unrelated IllegalArgumentExcepti…
…on (#17609)

Motivation:

`FixedChannelPool.release(...)` does not give back the acquired slot if
the release failed with an `IllegalArgumentException`:

```java
// Check if the exception was not because of we passed the Channel to the wrong pool.
if (!(cause instanceof IllegalArgumentException)) {
    decrementAndRunTaskQueue();
}
```

`SimpleChannelPool` uses `IllegalArgumentException` for "Channel ... was
not acquired from this ChannelPool", and this check has been there since
the pools were added. But the release also fails with any exception
thrown by user code, for example `ChannelPoolHandler.channelReleased()`,
`ChannelHealthChecker.isHealthy()` when the release health check is
enabled, or an overridden `offerChannel()`. All of these go through
`closeAndFail(...)`. If that exception is an `IllegalArgumentException`,
the channel is closed but still counted as acquired. The slot is lost
forever: with `maxConnections = 1` every later `acquire()` waits forever
or times out.

Modification:

- `SimpleChannelPool` fails the release of a channel that was not
acquired from the pool with a new package-private
`ChannelNotAcquiredFromPoolException` (with a `serialVersionUID`). It
extends `IllegalArgumentException` and keeps the message and the stack
trace, so users who catch or assert `IllegalArgumentException` are not
affected. The only visible difference is the class name: `toString()`
and logged stack traces now show
`io.netty.channel.pool.SimpleChannelPool$ChannelNotAcquiredFromPoolException:
Channel ... was not acquired from this ChannelPool` instead of
`java.lang.IllegalArgumentException: ...`.
- `FixedChannelPool` only skips the decrement for that exception.
- Add
`FixedChannelPoolTest.testReleaseFailsWithIllegalArgumentExceptionFromHandler`:
`maxConnections = 1` with a handler whose `channelReleased()` throws an
`IllegalArgumentException`. The release must fail with that exception,
the acquired count must drop to 0, and the next `acquire()` must
succeed.
- `testReleaseDifferentPool` still expects an
`IllegalArgumentException`, and now also asserts
`pool2.acquiredChannelCount() == 0` after the failed release, so the
wrong-pool release still does not give back a slot of the pool it was
released to.

Result:

A release that fails for any reason other than "not acquired from this
pool" always gives back its slot, so a buggy handler or health checker
can no longer shrink a `FixedChannelPool` for good.
  • Loading branch information

Uh oh!

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

@allthingssecurity @normanmaurer
allthingssecurity authored and normanmaurer committed Sep 29, 2026
commit eb25c1bbf01022298f762a98052a362ecc3fb0b2

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 @@ -307,7 +307,9 @@ public 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 @@ -295,8 +295,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 @@ -415,6 +414,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
42 changes: 41 additions & 1 deletion 42 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 @@ -209,7 +209,7 @@ public void testReleaseDifferentPool() throws Exception {
Channel sc = t.sb.bind(t.address).get();
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().get();

Expand All @@ -220,6 +220,9 @@ public void execute() throws Throwable {
}
});
assertInstanceOf(IllegalArgumentException.class, cause.getCause());

// 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 @@ -273,6 +276,43 @@ public void testReleaseClosed() throws Exception {
pool.close();
}

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

// Start server
Channel sc = t.sb.bind(t.address).get();
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
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.