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:
parent
42d2f79239
commit
f7a0a4db11
@ -19,6 +19,7 @@ import static org.jboss.netty.channel.Channels.*;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.channels.Selector;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@ -49,6 +50,7 @@ class NioServerSocketChannel extends AbstractServerChannel
|
|||||||
|
|
||||||
final ServerSocketChannel socket;
|
final ServerSocketChannel socket;
|
||||||
final Lock shutdownLock = new ReentrantLock();
|
final Lock shutdownLock = new ReentrantLock();
|
||||||
|
volatile Selector selector;
|
||||||
private final ServerSocketChannelConfig config;
|
private final ServerSocketChannelConfig config;
|
||||||
|
|
||||||
NioServerSocketChannel(
|
NioServerSocketChannel(
|
||||||
|
@ -174,7 +174,13 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
|
|||||||
private void close(NioServerSocketChannel channel, ChannelFuture future) {
|
private void close(NioServerSocketChannel channel, ChannelFuture future) {
|
||||||
boolean bound = channel.isBound();
|
boolean bound = channel.isBound();
|
||||||
try {
|
try {
|
||||||
|
if (channel.socket.isOpen()) {
|
||||||
channel.socket.close();
|
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
|
// Make sure the boss thread is not running so that that the future
|
||||||
// is notified after a new connection cannot be accepted anymore.
|
// is notified after a new connection cannot be accepted anymore.
|
||||||
@ -222,6 +228,8 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
|
|||||||
closeSelector();
|
closeSelector();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
channel.selector = selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -286,6 +294,7 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void closeSelector() {
|
private void closeSelector() {
|
||||||
|
channel.selector = null;
|
||||||
try {
|
try {
|
||||||
selector.close();
|
selector.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user