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

Conversation

@normanmaurer

@normanmaurer normanmaurer commented Sep 29, 2026

Copy link
Copy Markdown
Member
  • Don't leak FixedChannelPool slots on unrelated IllegalArgumentException (Don't leak FixedChannelPool slots on unrelated IllegalArgumentException #17609)
  • Port: Don't corrupt the pipeline when a handler context is removed twice (Don't corrupt the pipeline when a handler context is removed twice #17643)

Sorry, something went wrong.

Uh oh!

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

All reactions
allthingssecurity added 2 commits September 29, 2026 15:27
@allthingssecurity @normanmaurer
Don't leak FixedChannelPool slots on unrelated IllegalArgumentExcepti…
eb25c1b
…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.
@allthingssecurity @normanmaurer
Port: Don't corrupt the pipeline when a handler context is removed tw…
b7f8b13
…ice (#17643)

Motivation:

`DefaultChannelPipeline.atomicRemoveFromHandlerList(...)` is not
idempotent. A removed context keeps its `prev` / `next` pointers, and
`replace0(...)` leaves the old context with `prev = next = newCtx`.
Unlinking such a context a second time writes its stale neighbours back
into the list. For a replaced context the replacement then points to
itself.

There are three ways to get there:

1. `remove(handler)` / `replace(handler, ...)` look up the context
outside of the pipeline lock. Two threads that remove or replace the
same handler can both find the context and both unlink it. In a stress
harness (two threads running `remove(x)` and `replace(x -> y)` on a
`LocalChannel`), the list was corrupted after a few thousand iterations.
2. `callHandlerAdded0(...)` unlinks the context when `handlerAdded(...)`
throws, even if `handlerAdded(...)` already replaced or removed its own
handler. The same happens when a handler is replaced before the channel
is registered and its deferred `handlerAdded(...)` throws at
registration. Afterwards `fireChannelRead(...)` loops forever in
`findContextInbound(...)`.
3. `destroyDown(...)` unlinks a context that a `handlerRemoved(...)`
callback of a handler further down the pipeline has replaced. `close()`
then spins forever in `destroyDown(...)` and pins the event loop.

Modification:

- `atomicRemoveFromHandlerList(...)` checks under the lock that the
context is still linked (`ctx.prev.next == ctx`) and does nothing,
returning `false`, if it is not.
- `remove(...)` and `replace(...)` throw `NoSuchElementException` when
the context was removed or replaced after it was looked up, the same as
for a handler that is not in the pipeline. `removeIfExists(...)` returns
`null` in that case.
- `callHandlerAdded0(...)` and `destroyDown(...)` skip a context that is
no longer linked. Whoever unlinked it is already responsible for calling
`handlerRemoved(...)`, so it is still called exactly once.
- No public API changes.

Added tests to `DefaultChannelPipelineTest`:

- `testHandlerAddedReplacesItselfAndThrows` (path 2)
- `testHandlerReplacedBeforeRegistrationAndHandlerAddedThrows` (path 2,
deferred `handlerAdded`)
- `testCloseWhenHandlerRemovedReplacesOtherHandler` (path 3)
- `testRemoveOfHandlerReplacedConcurrently` (path 1, made deterministic
by holding the pipeline lock until the removing thread has looked up the
context and is blocked on the lock)
- `testHandlerAddedRemovesItselfAndThrows` (the
remove-instead-of-replace variant of path 2; this one already passed
before, since the list happened to stay consistent, and is added for
coverage)

The tests check that the list is consistent, that events still reach the
replacement handler and the tail, and that `handlerAdded` /
`handlerRemoved` are each called once. Without the fix, three of the
first four time out and `testRemoveOfHandlerReplacedConcurrently` fails.

Result:

The pipeline stays consistent when a handler context is removed more
than once, and none of the three paths can hang the channel anymore.

Behaviour change: when two threads race to remove or replace the same
handler, the call that loses now throws `NoSuchElementException` (as
documented on `ChannelPipeline.remove(...)` / `replace(...)` for a
handler that is not in the pipeline) instead of also "succeeding" and
corrupting the list. A call that comes slightly later already got this
exception before this change.

Also, `PendingHandlerAddedTask`'s rejected-executor path, which unlinks
the context, can no longer unlink a context that was removed before
registration a second time.
@normanmaurer normanmaurer closed this Sep 29, 2026
@normanmaurer
normanmaurer deleted the pipeline5 branch September 29, 2026 14:32
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

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

2 participants

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