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

Conversation

@allthingssecurity

@allthingssecurity allthingssecurity commented Sep 24, 2026 •
edited by normanmaurer
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Motivation:

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

// 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.

Testing:

  • Without the fix the new test fails:
    FixedChannelPoolTest.testReleaseFailsWithIllegalArgumentExceptionFromHandler:419 expected: <0> but was: <1>
  • With the fix: io.netty.channel.pool tests 35, 0 failures (FixedChannelPoolTest 18); transport module 403 tests, 0 failures, 9 skipped; checkstyle passes.
  • Standalone harness against the real classes: with an IllegalArgumentException from channelReleased(), acquiredChannelCount stayed at 1 and the next acquire() did not complete before the fix. After the fix the count is 0 and the next acquire() succeeds, the same as with an IllegalStateException.

Follow-up, pre-existing and not fixed here:

SimpleChannelPool.doReleaseChannel checks the owner with channel.attr(POOL_KEY).getAndSet(null) != this, so it clears the key even when the channel belongs to another pool. Releasing pool1's channel to pool2 therefore fails as expected but also removes pool1's key, and closes the channel. A later pool1.release(channel) then fails with ChannelNotAcquiredFromPoolException too, so pool1 never gives back that slot. I checked this with the real classes: after the wrong-pool release, pool1.release(channel) fails and pool1.acquiredChannelCount() stays 1. This is a misuse case (releasing to the wrong pool), and fixing it (for example, only clearing the key if it matches) changes behavior beyond this PR, so it is left for a separate change.

Sorry, something went wrong.

Uh oh!

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

All reactions
@allthingssecurity @claude
Don't leak FixedChannelPool slots on unrelated IllegalArgumentException
6f2db9e
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]>
@normanmaurer normanmaurer added this to the 4.2.19.Final milestone Sep 25, 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 Sep 25, 2026
@testlens-app

testlens-app Bot commented Sep 25, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 6f2db9e
▶️ Tests: 460226 executed
⚪️ Checks: 29/29 completed


Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer
normanmaurer merged commit 430fdff into netty:4.2 Sep 29, 2026
29 of 30 checks passed

Uh oh!

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

@netty-project-bot

netty-project-bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@netty-project-bot

netty-project-bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@allthingssecurity
allthingssecurity deleted the fix-fixedchannelpool-iae-slot-leak branch September 29, 2026 12:39
@normanmaurer

normanmaurer commented Sep 29, 2026

Copy link
Copy Markdown
Member

Port for 4.1 #17668
Port for 5.0: #17669

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer normanmaurer mentioned this pull request Sep 29, 2026
pipeline5 #17671
Closed
normanmaurer added a commit that referenced this pull request Sep 29, 2026
@normanmaurer @allthingssecurity
Port: Don't leak FixedChannelPool slots on unrelated IllegalArgumentE…
d00169c
…xception (#17609) (#17668)

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.

Co-authored-by: allthingssecurity <[email protected]>
normanmaurer added a commit that referenced this pull request Sep 29, 2026
@normanmaurer @allthingssecurity
Port: Don't leak FixedChannelPool slots on unrelated IllegalArgumentE…
9facd84
…xception (#17609) (#17669)

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.

Co-authored-by: allthingssecurity <[email protected]>
@normanmaurer normanmaurer removed 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 Oct 16, 2026
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@normanmaurer @allthingssecurity @lltopk
Port: Don't leak FixedChannelPool slots on unrelated IllegalArgumentE…
23e63cc
…xception (netty#17609) (netty#17668)

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.

Co-authored-by: allthingssecurity <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.19.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

@allthingssecurity @netty-project-bot @normanmaurer
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.