Search code examples
javanettynio

In Netty 4.1, when are the handlers in the pipeline removed after closing the channel on the server?


So, we are in the process of migrating from Netty 3.9 to Netty 4.1 on our production servers. There seems to be a difference in the way the ChannelHandlers are added and removed from the pipeline in both the versions. Specifically, after closing a channel on the server, I am logging the ChannelHandlers present in the pipeline at some point. While in Netty 4.1, the pipeline sometimes shows few or none of the handlers, in Netty 3.9, all the handlers are always present. All this after closing the channel reference. Is this expected? When does Netty (both in 3.9 and 4.1) remove all the handlers in the pipeline after a channel is closed?


Solution

  • In netty 4.x we remove all the handlers after each other from the pipeline when a channel is closed. This way we also execute handlerRemoved(...) which may is needed to release memory etc.