Skip to content
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.

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

ServerBootstrap.handler(...) will add handler before Channel is regis… #3933

Closed
wants to merge 1 commit into from

Conversation

normanmaurer
Copy link
Member

…tered.

Motivation:

If you set a ChannelHandler via ServerBootstrap.handler(...) it is added to the ChannelPipeline before the Channel is registered. This will lead to and IllegalStateException if a user tries to access the EventLoop in the ChannelHandler.handlerAdded(...) method.

Modifications:

Delay the adding of the ChannelHandler until the Channel was registered.

Result:

No more IllegalStateException.

@normanmaurer
Copy link
Member Author

@trustin please check

@normanmaurer normanmaurer self-assigned this Jul 3, 2015
@normanmaurer normanmaurer added this to the 4.0.30.Final milestone Jul 3, 2015
@@ -181,7 +177,11 @@ void init(Channel channel) throws Exception {
p.addLast(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(new ServerBootstrapAcceptor(
ChannelPipeline pipeline = ch.pipeline();
if (handler() != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handler() could be extracted into a local variable.

@trustin
Copy link
Member

trustin commented Jul 7, 2015

LGTM. Please feel free to cherry-pick after addressing one nit.

…tered.

Motivation:

If you set a ChannelHandler via ServerBootstrap.handler(...) it is added to the ChannelPipeline before the Channel is registered. This will lead to and IllegalStateException if a user tries to access the EventLoop in the ChannelHandler.handlerAdded(...) method.

Modifications:

Delay the adding of the ChannelHandler until the Channel was registered.

Result:

No more IllegalStateException.
@normanmaurer
Copy link
Member Author

@trustin thanks addressed.

Cherry-picked into 4.0 (5804cb3), 4.1 (dd6ac55) and master (5d5bf1a)

@normanmaurer normanmaurer deleted the serverbootstrap_handler_fix branch July 7, 2015 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants