GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||
GeezerVison is showing github.com — Don't leak FixedChannelPool slots on unrelated IllegalArgumentException by allthingssecurity · Pull Request #17609 · netty/netty Conversation
|
✅ All tests passed ✅🏷️ Commit: 6f2db9e Learn more about TestLens at testlens.app/docs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Could not create auto-port PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Could not create auto-port PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…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]>
…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]>
…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]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.