Repository navigation
POOL: Release Channel when SimpleChannelPool acquire is cancelled - #17569
Merged
normanmaurer merged 1 commit intoSep 21, 2026
Merged
Conversation
Motivation: SimpleChannelPool hands an acquired Channel to the caller's Promise in two places. notifyConnect() completes the Promise with trySuccess(...) and releases the Channel back into the pool when the Promise turns out to be completed already, which is what happens when the caller cancelled the acquire. notifyHealthCheck(), the path taken when an already pooled Channel is reused, still completes the Promise with setSuccess(...). So when the acquire Promise is completed while the health check of a pooled Channel is still pending, setSuccess(...) throws IllegalStateException. The surrounding catch routes it to closeAndFail(...), which closes a healthy pooled Channel instead of offering it back. handler.channelAcquired(...) has already been invoked at that point, so the matching channelReleased(...) callback never arrives and a ChannelPoolHandler that tracks acquire and release counts stays out of balance for the rest of the pool's lifetime. FixedChannelPool.AcquireListener already guards the same race the same way. Modifications: - Complete the acquire Promise in notifyHealthCheck() with trySuccess(...) and release the Channel again when it was completed already, mirroring what notifyConnect() does. - Add a regression test that cancels the acquire Promise while the health check of a pooled Channel is pending, and asserts that the Channel stays active, is handed back by the next acquire, and that the pool handler callbacks stay balanced. Result: Cancelling an acquire no longer destroys a pooled Channel, and the channelAcquired and channelReleased callbacks stay balanced.
🚨 TestLens detected 1 failed test 🚨Here is what you can do:
Test SummaryBuild PR / macos-x86_64-java11-boringssl build > Netty/Transport/Native/KQueue
🏷️ Commit: f82323a Test FailuresKQueueJdkLoopbackSocketSslEchoTest > testSslEcho(SslContext, SslContext, Renegotiation, boolean, boolean, boolean, boolean, boolean, TestInfo) > 49: serverEngine = io.netty.handler.ssl.JdkSslServerContext@1c98b4eb, clientEngine = io.netty.handler.ssl.JdkSslClientContext@45801322, renegotiation = CLIENT_INITIATED(TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA), serverUsesDelegatedTaskExecutor = true, clientUsesDelegatedTaskExecutor = false, autoRead = false, useChunkedWriteHandler = false, useCompositeByteBuf = false (Netty/Transport/Native/KQueue in Build PR / macos-x86_64-java11-boringssl build)Rerun ControlsNote Checks are currently running using the configuration below. Select tests to mute in this pull request: 🔲 KQueueJdkLoopbackSocketSslEchoTest > testSslEcho(SslContext, SslContext, Renegotiation, boolean, boolean, boolean, boolean, boolean, TestInfo) Reuse successful test results: 🔲 ♻️ Only rerun the tests that failed or were muted before Click the checkbox to trigger a rerun: 🔲 Rerun jobs Learn more about TestLens at testlens.app/docs. |
Contributor
|
Auto-port PR for 4.1: #17578 |
Contributor
|
Could not create auto-port PR. |
Member
|
Port for 5.0: #17580 |
normanmaurer
added a commit
that referenced
this pull request
Sep 21, 2026
…ed (#17569) (#17580) `notifyConnect()` completes the acquire `Promise` with `trySuccess(...)` and releases the `Channel` if already completed. `notifyHealthCheck()`, the reuse path, still uses `setSuccess(...)`. `doHealthCheck` runs via `loop.execute(...)` when `acquire()` is called off its event loop, so a cancel can land while that task is queued, even with the stock `ACTIVE` checker. `setSuccess(...)` then throws into `closeAndFail(...)`: a healthy pooled `Channel` is closed and its `channelAcquired(...)` gets no `channelReleased(...)`. `notifyHealthCheck()` mirrors `notifyConnect()`, plus a regression test on a hand-completed health check. Reverting just the source hunk fails that test on `releasedCount()`, 2 expected, 1 seen. With it, 34/34. Co-authored-by: renechoi <[email protected]>
normanmaurer
pushed a commit
that referenced
this pull request
Sep 22, 2026
…7569) `notifyConnect()` completes the acquire `Promise` with `trySuccess(...)` and releases the `Channel` if already completed. `notifyHealthCheck()`, the reuse path, still uses `setSuccess(...)`. `doHealthCheck` runs via `loop.execute(...)` when `acquire()` is called off its event loop, so a cancel can land while that task is queued, even with the stock `ACTIVE` checker. `setSuccess(...)` then throws into `closeAndFail(...)`: a healthy pooled `Channel` is closed and its `channelAcquired(...)` gets no `channelReleased(...)`. `notifyHealthCheck()` mirrors `notifyConnect()`, plus a regression test on a hand-completed health check. Reverting just the source hunk fails that test on `releasedCount()`, 2 expected, 1 seen. With it, 34/34. (cherry picked from commit 6b257ce)
normanmaurer
added a commit
that referenced
this pull request
Sep 22, 2026
…s cancelled (#17578) Auto-port of #17569 to 4.1 Cherry-picked commit: 6b257ce --- ### Motivation `notifyConnect()` completes the acquire `Promise` with `trySuccess(...)` and releases the `Channel` if already completed. `notifyHealthCheck()`, the reuse path, still uses `setSuccess(...)`. `doHealthCheck` runs via `loop.execute(...)` when `acquire()` is called off its event loop, so a cancel can land while that task is queued, even with the stock `ACTIVE` checker. `setSuccess(...)` then throws into `closeAndFail(...)`: a healthy pooled `Channel` is closed and its `channelAcquired(...)` gets no `channelReleased(...)`. #17287 gave `FixedChannelPool` this guard. ### Modification `notifyHealthCheck()` mirrors `notifyConnect()`, plus a regression test on a hand-completed health check. ### Result Reverting just the source hunk fails that test on `releasedCount()`, 2 expected, 1 seen. With it, 34/34. --------- Co-authored-by: renechoi <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
lltopk
pushed a commit
to lltopk/netty
that referenced
this pull request
Oct 24, 2026
…s cancelled (netty#17578) Auto-port of netty#17569 to 4.1 Cherry-picked commit: 6b257ce --- ### Motivation `notifyConnect()` completes the acquire `Promise` with `trySuccess(...)` and releases the `Channel` if already completed. `notifyHealthCheck()`, the reuse path, still uses `setSuccess(...)`. `doHealthCheck` runs via `loop.execute(...)` when `acquire()` is called off its event loop, so a cancel can land while that task is queued, even with the stock `ACTIVE` checker. `setSuccess(...)` then throws into `closeAndFail(...)`: a healthy pooled `Channel` is closed and its `channelAcquired(...)` gets no `channelReleased(...)`. netty#17287 gave `FixedChannelPool` this guard. ### Modification `notifyHealthCheck()` mirrors `notifyConnect()`, plus a regression test on a hand-completed health check. ### Result Reverting just the source hunk fails that test on `releasedCount()`, 2 expected, 1 seen. With it, 34/34. --------- Co-authored-by: renechoi <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
notifyConnect()completes the acquirePromisewithtrySuccess(...)and releases theChannelif already completed.notifyHealthCheck(), the reuse path, still usessetSuccess(...).doHealthCheckruns vialoop.execute(...)whenacquire()is called off its event loop, so a cancel can land while that task is queued, even with the stockACTIVEchecker.setSuccess(...)then throws intocloseAndFail(...): a healthy pooledChannelis closed and itschannelAcquired(...)gets nochannelReleased(...).#17287 gave
FixedChannelPoolthis guard.Modification
notifyHealthCheck()mirrorsnotifyConnect(), plus a regression test on a hand-completed health check.Result
Reverting just the source hunk fails that test on
releasedCount(), 2 expected, 1 seen. With it, 34/34.