Skip to content

Misleading comment in ChannelInitializer.initChannel(...) #16846

@doxlik

Description

@doxlik

Hi, and thank you for Netty.

While reading current 4.2 ChannelInitializer, I noticed what looks like a small misleading comment.

In initChannel(ChannelHandlerContext ctx), the catch block says:

// Explicitly call exceptionCaught(...) as we removed the handler before calling initChannel(...).
// We do so to prevent multiple calls to initChannel(...).
exceptionCaught(ctx, cause);

But in the current code, the initializer is removed later in the finally block:

finally {
    if (!ctx.isRemoved()) {
        ctx.pipeline().remove(this);
    }
}

So it looks like the handler is not removed before calling initChannel((C) ctx.channel()).

My understanding is that re-entrance is guarded by initMap.add(ctx), and the initializer is removed after the init attempt.

Would it make sense to update this comment to avoid confusion?

Code link:
https://github.com/netty/netty/blob/4.2/transport/src/main/java/io/netty/channel/ChannelInitializer.java#L783-L803

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions