Fixed issue: NETTY-214 NIO socket / datagram transport sometimes does not shut down
* Fixed a race condition in NioWorker.close() and NioDatagramWorker.close()
This commit is contained in:
parent
be32586d50
commit
1574fc3188
@ -648,15 +648,18 @@ class NioDatagramWorker implements Runnable {
|
||||
final ChannelFuture future) {
|
||||
NioDatagramWorker worker = channel.worker;
|
||||
Selector selector = worker.selector;
|
||||
SelectionKey key = channel.getDatagramChannel().keyFor(selector);
|
||||
if (key != null) {
|
||||
key.cancel();
|
||||
}
|
||||
|
||||
boolean connected = channel.isConnected();
|
||||
boolean bound = channel.isBound();
|
||||
try {
|
||||
channel.getDatagramChannel().close();
|
||||
synchronized (channel.interestOpsLock) {
|
||||
SelectionKey key = channel.getDatagramChannel().keyFor(selector);
|
||||
if (key != null) {
|
||||
key.cancel();
|
||||
}
|
||||
channel.getDatagramChannel().close();
|
||||
}
|
||||
|
||||
if (channel.setClosed()) {
|
||||
future.setSuccess();
|
||||
if (connected) {
|
||||
|
@ -562,15 +562,18 @@ class NioWorker implements Runnable {
|
||||
static void close(NioSocketChannel channel, ChannelFuture future) {
|
||||
NioWorker worker = channel.worker;
|
||||
Selector selector = worker.selector;
|
||||
SelectionKey key = channel.socket.keyFor(selector);
|
||||
if (key != null) {
|
||||
key.cancel();
|
||||
}
|
||||
|
||||
boolean connected = channel.isConnected();
|
||||
boolean bound = channel.isBound();
|
||||
try {
|
||||
channel.socket.close();
|
||||
synchronized (channel.interestOpsLock) {
|
||||
SelectionKey key = channel.socket.keyFor(selector);
|
||||
if (key != null) {
|
||||
key.cancel();
|
||||
}
|
||||
channel.socket.close();
|
||||
}
|
||||
|
||||
if (channel.setClosed()) {
|
||||
future.setSuccess();
|
||||
if (connected) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user