Skip to content

Release channel when FixedChannelPool acquire is cancelled - #17287

Merged
normanmaurer merged 1 commit into
netty:4.2from
Gimini-3:fix-fixed-channel-pool-cancelled-acquire
Aug 14, 2026
Merged

normanmaurer merged 1 commit into
netty:4.2from
Gimini-3:fix-fixed-channel-pool-cancelled-acquire

Conversation

@Gimini-3

Copy link
Copy Markdown
Contributor

Motivation:

FixedChannelPool increments acquiredChannelCount before its internal acquire completes. If the caller cancels the original promise and the internal acquire succeeds, setSuccess throws and the acquired channel is neither returned nor closed. The slot remains occupied, pending acquires may stall, and pool close cannot reach the undelivered channel.

Modification:

Complete the caller promise with trySuccess and release the channel when the promise was already completed. Add deterministic coverage for cancellation before delivery, cancelled pending acquires, queue progression, slot accounting, and pool-close races.

Result:

Cancelled acquires no longer leak a channel or an acquired slot, and pending acquires continue once the undelivered channel is returned.

Fixes #9669.

Validation:

  • ./mvnw -pl transport -Dtest=FixedChannelPoolTest test
  • ./mvnw -pl transport test (394 tests, 0 failures, 0 errors, 9 skipped)

@Gimini-3
Gimini-3 marked this pull request as ready for review August 14, 2026 07:54
@testlens-app

testlens-app Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

🚨 TestLens detected 1 failed test 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Build PR / linux-x86_64-java11-awslc build > Netty/Codec/HTTP2

Test Runs Flakiness
Http2ConnectionRoundtripTest > createStreamAfterReceiveGoAwayShouldNotSendGoAway() ❌ ✅ 1% 🟡

Build PR / macos-aarch64-java11-boringssl build > Netty/Transport/Native/KQueue

Test Runs Flakiness
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeDirectByteBuf(TestInfo) ✅ ❌ 5% 🟠
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeHeapByteBuf(TestInfo) ❌ ✅ 1% 🟡

🏷️ Commit: 76fae38
▶️ Tests: 43220 executed
🟡 Checks: 22/24 completed

Test Failures

KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeDirectByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java11-boringssl build)
org.opentest4j.AssertionFailedError
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend0(DatagramUnicastTest.java:360)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend(DatagramUnicastTest.java:192)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeDirectByteBuf(DatagramUnicastTest.java:121)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$3.run(DatagramUnicastTest.java:112)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$3.run(DatagramUnicastTest.java:109)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeDirectByteBuf(DatagramUnicastTest.java:109)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

Muted Tests

Note

Checks are currently running using the configuration below.

Select tests to mute in this pull request:

🔲 Http2ConnectionRoundtripTest > createStreamAfterReceiveGoAwayShouldNotSendGoAway()
🔲 KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeDirectByteBuf(TestInfo)
🔲 KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeHeapByteBuf(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.

@normanmaurer normanmaurer added this to the 4.2.18.Final milestone Aug 14, 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 Aug 14, 2026
@normanmaurer
normanmaurer merged commit 21dd89e into netty:4.2 Aug 14, 2026
36 of 39 checks passed
@netty-project-bot

Copy link
Copy Markdown
Contributor

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

@normanmaurer

Copy link
Copy Markdown
Member

Port for 5.0 #17288

@netty-project-bot

Copy link
Copy Markdown
Contributor

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

@normanmaurer

Copy link
Copy Markdown
Member

Need #17289 to make it easier to backport change to 4.1

@normanmaurer

Copy link
Copy Markdown
Member

Pr for 4:1 #17291

normanmaurer added a commit that referenced this pull request Aug 15, 2026
…17288)

Motivation:

`FixedChannelPool` increments `acquiredChannelCount` before its internal
acquire completes. If the caller cancels the original promise and the
internal acquire succeeds, `setSuccess` throws and the acquired channel
is neither returned nor closed. The slot remains occupied, pending
acquires may stall, and pool close cannot reach the undelivered channel.

Modification:

Complete the caller promise with `trySuccess` and release the channel
when the promise was already completed. Add deterministic coverage for
cancellation before delivery, cancelled pending acquires, queue
progression, slot accounting, and pool-close races.

Result:

Cancelled acquires no longer leak a channel or an acquired slot, and
pending acquires continue once the undelivered channel is returned.

Fixes #9669.

Validation:

- `./mvnw -pl transport -Dtest=FixedChannelPoolTest test`
- `./mvnw -pl transport test` (394 tests, 0 failures, 0 errors, 9
skipped)

---------

Co-authored-by: Gimin Kim <[email protected]>
normanmaurer added a commit that referenced this pull request Aug 16, 2026
…17291)

Motivation:

`FixedChannelPool` increments `acquiredChannelCount` before its internal
acquire completes. If the caller cancels the original promise and the
internal acquire succeeds, `setSuccess` throws and the acquired channel
is neither returned nor closed. The slot remains occupied, pending
acquires may stall, and pool close cannot reach the undelivered channel.

Modification:

Complete the caller promise with `trySuccess` and release the channel
when the promise was already completed. Add deterministic coverage for
cancellation before delivery, cancelled pending acquires, queue
progression, slot accounting, and pool-close races.

Result:

Cancelled acquires no longer leak a channel or an acquired slot, and
pending acquires continue once the undelivered channel is returned.

Fixes #9669.

Validation:

- `./mvnw -pl transport -Dtest=FixedChannelPoolTest test`
- `./mvnw -pl transport test` (394 tests, 0 failures, 0 errors, 9
skipped)

---------

Co-authored-by: Gimin Kim <[email protected]>
normanmaurer pushed a commit that referenced this pull request Sep 21, 2026
…7569)

### 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.
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]>
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
@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
…) (netty#17291)

Motivation:

`FixedChannelPool` increments `acquiredChannelCount` before its internal
acquire completes. If the caller cancels the original promise and the
internal acquire succeeds, `setSuccess` throws and the acquired channel
is neither returned nor closed. The slot remains occupied, pending
acquires may stall, and pool close cannot reach the undelivered channel.

Modification:

Complete the caller promise with `trySuccess` and release the channel
when the promise was already completed. Add deterministic coverage for
cancellation before delivery, cancelled pending acquires, queue
progression, slot accounting, and pool-close races.

Result:

Cancelled acquires no longer leak a channel or an acquired slot, and
pending acquires continue once the undelivered channel is returned.

Fixes netty#9669.

Validation:

- `./mvnw -pl transport -Dtest=FixedChannelPoolTest test`
- `./mvnw -pl transport test` (394 tests, 0 failures, 0 errors, 9
skipped)

---------

Co-authored-by: Gimin Kim <[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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IllegalStateException: complete already on notifyListener / operationComplete

3 participants