question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding handlers to a closed Channel's pipeline

See original GitHub issue

It appears the a ChannelPipeline will happily add a handler to a closed Channel’s pipeline and will call handlerAdded(...) but will not call handlerRemoved(...) or blow up in some other way to let the caller know that things aren’t in a good state.

Just wondering if there wouldn’t be edge cases where we’d potentially leak resources (e.g. SslHandler#handlerRemoved0(...) which is supposed to release a reference counted SSLEngine).

Expected behavior

Fail with Exception or handlerRemoved(...) getting called after handlerAdded(...)

Actual behavior

handlerAdded(...) getting called as if everything is ok

Steps to reproduce

Minimal yet complete reproducer code (or URL to code)

@Test
public void testHandlerAfterClose() throws Exception {
  EmbeddedChannel channel = new EmbeddedChannel();
  channel.close().syncUninterruptibly();
  
  assertFalse(channel.isActive());
  
  final CountDownLatch addedLatch = new CountDownLatch(1);
  final CountDownLatch removedLatch = new CountDownLatch(1);
  
  ChannelPipeline pipeline = channel.pipeline();
  pipeline.addLast(new ChannelHandlerAdapter() {
    @Override
    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
      addedLatch.countDown();
    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
      removedLatch.countDown();
    }
  });
  
  assertTrue(addedLatch.await(1L, TimeUnit.SECONDS));
  assertTrue(removedLatch.await(1L, TimeUnit.SECONDS));
}

Netty version

JVM version (e.g. java -version)

OS version (e.g. uname -a)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
normanmaurercommented, May 23, 2017

@Scottmitch I think non static exception is better as I not expect this to be thrown often and it will be better to have some context

0reactions
normanmaurercommented, Oct 11, 2019

Yes I missed to close this 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChannelPipeline (Netty API Reference (4.0.56.Final))
A user is supposed to have one or more ChannelHandler s in a pipeline to receive I/O events (e.g. read) and to request...
Read more >
Pipeline handler ordering and other questions - SwiftNIO
I'm currently implementing an MQTT broker using SwiftNIO and I'm having trouble understanding a few things. First and foremost, I can't seem ...
Read more >
How to dynamic add/remove handlers outside of a handler
I know netty supported dynamically adding/removing handlers in pipeline, but however I could find almost all the samples said how to implement ...
Read more >
Example usage for io.netty.channel Channel pipeline - Java2s.com
Usage ; new DefaultSmppSession(SmppSession.Type.CLIENT, config, channel, sessionHandler, monitorExecutor); // add SSL handler if ; if (sslConfig == null) throw ...
Read more >
A Tour of Netty. Introduction | by Kondah Mouad | Geek Culture
Whenever a channel is created, a ChannelPipeline is created and ... step would be to initialise our channel, that is, adding handlers ect…...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found