Dravenj
Dravenj

Reputation: 71

Netty IdleStateAwareHandler per connection not channel

I have a server and a client that have their own bootstrap. My issue is that different connections are used for different purposes. One is used for control channel(communicating to server and back) and then other connections are established to do data transfers. I programmatically add the idlestate handler only to the connections pipeline that needs it however after debugging I am finding that regardless of the connection, the channel is always the same. So my data transfers are impacting the keep alive. I was able to see this by adding debugging to netty IdleStateHandler and outputting the channel id. Most likely my misunderstanding but I thought each connection would be its own channel.

Any idea on how to add idle state handler to specific connections?

Upvotes: 0

Views: 213

Answers (2)

Dravenj
Dravenj

Reputation: 71

Found out that the location of the idlestatehandler was my issue. It was added after the sslhandler which caused invalid state to occur. Moved it before the ssl handler and it works appropriately.

Upvotes: 1

Dmitriy Dumanskiy
Dmitriy Dumanskiy

Reputation: 12827

Channel is an abstraction over the connection in Netty. So, every time you initialize pipeline with IdleStateHandler in it, like this:

 public class MyChannelInitializer extends {ChannelInitializer, Channel} {
     @Override
     public void initChannel(Channel channel) {
         channel.pipeline().addLast("idleStateHandler", new  IdleStateHandler(60, 30, 0));
         channel.pipeline().addLast("myHandler", new MyHandler());
     }
 }

You assign new IdleStateHandler per new connection/channel. Without the code it hard to give a more precise answer.

Most probably, you either using the same instance of IdleStateHandler between channels or your client opens only 1 connection instead of 2.

Upvotes: 0

Related Questions