[#239] IdleStateHandler and ReadTimeoutHandler starts two timers

- Ensure initialize does not start timer twice
This commit is contained in:
Trustin Lee 2012-08-21 20:13:44 +09:00
parent a93ada2031
commit 31a51b4937
2 changed files with 33 additions and 18 deletions

View File

@ -309,8 +309,13 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler
// Avoid the case where destroy() is called before scheduling timeouts.
// See: https://github.com/netty/netty/issues/143
if (state.destroyed) {
return;
synchronized (state) {
switch (state.state) {
case 1:
case 2:
return;
}
state.state = 1;
}
state.lastReadTime = state.lastWriteTime = System.currentTimeMillis();
@ -332,11 +337,12 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler
}
private static void destroy(ChannelHandlerContext ctx) {
State state;
synchronized (ctx) {
state = state(ctx);
state.destroyed = true;
State state = state(ctx);
synchronized (state) {
if (state.state != 1) {
return;
}
state.state = 2;
}
if (state.readerIdleTimeout != null) {
@ -478,9 +484,8 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler
}
private static final class State {
State() {
super();
}
// 0 - none, 1 - initialized, 2 - destroyed
int state;
volatile Timeout readerIdleTimeout;
volatile long lastReadTime;
@ -490,6 +495,8 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler
volatile Timeout allIdleTimeout;
volatile boolean destroyed;
State() {
super();
}
}
}

View File

@ -189,8 +189,13 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler
// Avoid the case where destroy() is called before scheduling timeouts.
// See: https://github.com/netty/netty/issues/143
if (state.destroyed) {
return;
synchronized (state) {
switch (state.state) {
case 1:
case 2:
return;
}
state.state = 1;
}
if (timeoutMillis > 0) {
@ -199,10 +204,12 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler
}
private static void destroy(ChannelHandlerContext ctx) {
State state;
synchronized (ctx) {
state = state(ctx);
state.destroyed = true;
State state = state(ctx);
synchronized (state) {
if (state.state != 1) {
return;
}
state.state = 2;
}
if (state.timeout != null) {
@ -269,9 +276,10 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler
}
private static final class State {
// 0 - none, 1 - initialized, 2 - destroyed
int state;
volatile Timeout timeout;
volatile long lastReadTime = System.currentTimeMillis();
volatile boolean destroyed;
State() {
super();