IdleStateHandler.initialize() and ReadTimeoutHandler.initialize() must not be called if their pipeline is not attached yet. Otherwise the timeout might occur even before the connection is established.

This commit is contained in:
Trustin Lee 2009-12-17 10:14:22 +00:00
parent 2bf4dfcfb9
commit 3fcfc910e1
2 changed files with 10 additions and 4 deletions

View File

@ -201,7 +201,10 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler
}
public void beforeAdd(ChannelHandlerContext ctx) throws Exception {
initialize(ctx);
if (ctx.getPipeline().isAttached()) {
// channelOpen() has been called already - initialize here instead.
initialize(ctx);
}
}
public void afterAdd(ChannelHandlerContext ctx) throws Exception {
@ -219,7 +222,7 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
lastReadTime = lastWriteTime = System.currentTimeMillis();
initialize(ctx);
}
@Override

View File

@ -120,7 +120,10 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler
}
public void beforeAdd(ChannelHandlerContext ctx) throws Exception {
initialize(ctx);
if (ctx.getPipeline().isAttached()) {
// channelOpen() has been called already - initialize here instead.
initialize(ctx);
}
}
public void afterAdd(ChannelHandlerContext ctx) throws Exception {
@ -138,7 +141,7 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
updateLastReadTime();
initialize(ctx);
ctx.sendUpstream(e);
}