Related issue: NETTY-256 (A race condition during the recommended server shutdown procedure)

* Fixed a failing test (NioServerSocketShutdownTimeTest) by waking up the selector explicitly
This commit is contained in:
Trustin Lee 2009-11-30 21:19:50 +00:00
parent 42d2f79239
commit f7a0a4db11
2 changed files with 12 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import static org.jboss.netty.channel.Channels.*;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@ -49,6 +50,7 @@ class NioServerSocketChannel extends AbstractServerChannel
final ServerSocketChannel socket;
final Lock shutdownLock = new ReentrantLock();
volatile Selector selector;
private final ServerSocketChannelConfig config;
NioServerSocketChannel(

View File

@ -174,7 +174,13 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
private void close(NioServerSocketChannel channel, ChannelFuture future) {
boolean bound = channel.isBound();
try {
channel.socket.close();
if (channel.socket.isOpen()) {
channel.socket.close();
Selector selector = channel.selector;
if (selector != null) {
selector.wakeup();
}
}
// Make sure the boss thread is not running so that that the future
// is notified after a new connection cannot be accepted anymore.
@ -222,6 +228,8 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
closeSelector();
}
}
channel.selector = selector;
}
public void run() {
@ -286,6 +294,7 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
}
private void closeSelector() {
channel.selector = null;
try {
selector.close();
} catch (Exception e) {