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

pipeline5 #17671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
normanmaurer wants to merge 2 commits into 5.0 from pipeline5

Uh oh!

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

Closed

pipeline5 #17671

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
eb25c1b
Don't leak FixedChannelPool slots on unrelated IllegalArgumentExcepti…
allthingssecurity Sep 29, 2026
b7f8b13
Port: Don't corrupt the pipeline when a handler context is removed tw…
allthingssecurity Sep 29, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view

There are no files selected for viewing

64 changes: 53 additions & 11 deletions 64 transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -358,24 +358,40 @@ public final <T extends ChannelHandler> T removeIfExists(ChannelHandler handler)

@SuppressWarnings("unchecked")
private <T extends ChannelHandler> T removeIfExists(ChannelHandlerContext ctx) {
if (ctx == null) {
if (ctx == null || !tryRemove((AbstractChannelHandlerContext) ctx)) {
return null;
}
return (T) remove((AbstractChannelHandlerContext) ctx).handler();
return (T) ctx.handler();
}

private AbstractChannelHandlerContext remove(final AbstractChannelHandlerContext ctx) {
if (!tryRemove(ctx)) {
// The context was removed or replaced concurrently after it was looked up.
throw new NoSuchElementException(ctx.name());
}
return ctx;
}

/**
* Removes the given context from the pipeline and schedules the call of
* {@link ChannelHandler#handlerRemoved(ChannelHandlerContext)}.
*
* @return {@code false} if the context was not part of the pipeline anymore, in which case nothing is done.
*/
private boolean tryRemove(final AbstractChannelHandlerContext ctx) {
assert ctx != head && ctx != tail;

synchronized (this) {
atomicRemoveFromHandlerList(ctx);
if (!atomicRemoveFromHandlerList(ctx)) {
return false;
}

// If the registered is false it means that the channel was not registered on an eventloop yet.
// In this case we remove the context from the pipeline and add a task that will call
// ChannelHandler.handlerRemoved(...) once the channel is registered.
if (!registered) {
callHandlerCallbackLater(ctx, false);
return ctx;
return true;
}

EventExecutor executor = ctx.executor();
Expand All @@ -386,21 +402,38 @@ public void run() {
callHandlerRemoved0(ctx);
}
});
return ctx;
return true;
}
}
callHandlerRemoved0(ctx);
return ctx;
return true;
}

/**
* Returns {@code true} if the given context is still linked into the pipeline. A removed context keeps its
* {@code prev} and {@code next} pointers (and a replaced context points to its replacement), so the check must
* be done by looking at the neighbour.
*/
private boolean isLinked(AbstractChannelHandlerContext ctx) {
assert Thread.holdsLock(this);
return ctx.prev.next == ctx;
}

/**
* Method is synchronized to make the handler removal from the double linked list atomic.
*
* @return {@code false} if the context was already removed or replaced, in which case the list is not modified.
*/
private synchronized void atomicRemoveFromHandlerList(AbstractChannelHandlerContext ctx) {
private synchronized boolean atomicRemoveFromHandlerList(AbstractChannelHandlerContext ctx) {
if (!isLinked(ctx)) {
// Unlinking the context again would link its stale neighbours back into the pipeline.
return false;
}
AbstractChannelHandlerContext prev = ctx.prev;
AbstractChannelHandlerContext next = ctx.next;
prev.next = next;
next.prev = prev;
return true;
}

@Override
Expand Down Expand Up @@ -443,6 +476,10 @@ private ChannelHandler replace(

final AbstractChannelHandlerContext newCtx;
synchronized (this) {
if (!isLinked(ctx)) {
// The context was removed or replaced concurrently after it was looked up.
throw new NoSuchElementException(ctx.name());
}
checkMultiplicity(newHandler);
if (newName == null) {
newName = generateName(newHandler);
Expand Down Expand Up @@ -517,8 +554,11 @@ private void callHandlerAdded0(final AbstractChannelHandlerContext ctx) {
} catch (Throwable t) {
boolean removed = false;
try {
atomicRemoveFromHandlerList(ctx);
ctx.callHandlerRemoved(t);
// If handlerAdded(...) already removed or replaced the handler, whoever did that is responsible for
// calling handlerRemoved(...).
if (atomicRemoveFromHandlerList(ctx)) {
ctx.callHandlerRemoved(t);
}
removed = true;
} catch (Throwable t2) {
if (logger.isWarnEnabled()) {
Expand Down Expand Up @@ -806,8 +846,10 @@ private void destroyDown(Thread currentThread, AbstractChannelHandlerContext ctx

final EventExecutor executor = ctx.executor();
if (inEventLoop || executor.inEventLoop(currentThread)) {
atomicRemoveFromHandlerList(ctx);
callHandlerRemoved0(ctx);
// Skip a context that a handlerRemoved(...) callback already removed or replaced.
if (atomicRemoveFromHandlerList(ctx)) {
callHandlerRemoved0(ctx);
}
} else {
final AbstractChannelHandlerContext finalCtx = ctx;
executor.execute(new Runnable() {
Expand Down
4 changes: 3 additions & 1 deletion 4 transport/src/main/java/io/netty/channel/pool/FixedChannelPool.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ public void release(final Channel channel, final Promise<Void> promise) {
} else {
Throwable cause = future.cause();
// Check if the exception was not because of we passed the Channel to the wrong pool.
if (!(cause instanceof IllegalArgumentException)) {
// Other failures (for example an IllegalArgumentException thrown by the ChannelPoolHandler)
// must still give back the slot.
if (!(cause instanceof ChannelNotAcquiredFromPoolException)) {
decrementAndRunTaskQueue();
}
promise.setFailure(future.cause());
Expand Down
17 changes: 15 additions & 2 deletions 17 transport/src/main/java/io/netty/channel/pool/SimpleChannelPool.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ private void doReleaseChannel(Channel channel, Promise<Void> promise) {
if (channel.attr(POOL_KEY).getAndSet(null) != this) {
closeAndFail(channel,
// Better include a stacktrace here as this is an user error.
new IllegalArgumentException(
"Channel " + channel + " was not acquired from this ChannelPool"),
new ChannelNotAcquiredFromPoolException(channel),
promise);
} else {
if (releaseHealthCheck) {
Expand Down Expand Up @@ -415,6 +414,20 @@ public Void call() throws Exception {
});
}

/**
* Fails the release of a {@link Channel} that was not acquired from this pool. This lets {@link FixedChannelPool}
* tell it apart from other release failures, which may also be {@link IllegalArgumentException}s thrown by user
* code.
*/
static final class ChannelNotAcquiredFromPoolException extends IllegalArgumentException {

private static final long serialVersionUID = -7390314262213853178L;

ChannelNotAcquiredFromPoolException(Channel channel) {
super("Channel " + channel + " was not acquired from this ChannelPool");
}
}

private static final class ChannelPoolFullException extends IllegalStateException {

private ChannelPoolFullException() {
Expand Down
Loading
Oops, something went wrong.

Uh oh!

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

Loading
Oops, something went wrong.

Uh oh!

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

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.