Added the comment as suggested by Thomas Bocek
This commit is contained in:
parent
2fa19ff845
commit
404abfd198
@ -645,6 +645,13 @@ class NioDatagramWorker implements Runnable {
|
||||
boolean connected = channel.isConnected();
|
||||
boolean bound = channel.isBound();
|
||||
try {
|
||||
// It is necessary to cancel all keys before closing a socket
|
||||
// because the shutdown flag in the Selector loop is set only when
|
||||
// all keys are cancelled. Thus, SocketChannel.close() and
|
||||
// SelectionKey.cancel() must be placed in a synchronized block.
|
||||
// Otherwise SocketChannel.register() in RegisterTask can be called
|
||||
// after cancel(), but before close(), resulting in the infinite
|
||||
// Selector loop that refuses to shut down due to the dangling keys.
|
||||
synchronized (channel.interestOpsLock) {
|
||||
SelectionKey key = channel.getDatagramChannel().keyFor(selector);
|
||||
if (key != null) {
|
||||
|
@ -559,6 +559,13 @@ class NioWorker implements Runnable {
|
||||
boolean connected = channel.isConnected();
|
||||
boolean bound = channel.isBound();
|
||||
try {
|
||||
// It is necessary to cancel all keys before closing a socket
|
||||
// because the shutdown flag in the Selector loop is set only when
|
||||
// all keys are cancelled. Thus, SocketChannel.close() and
|
||||
// SelectionKey.cancel() must be placed in a synchronized block.
|
||||
// Otherwise SocketChannel.register() in RegisterTask can be called
|
||||
// after cancel(), but before close(), resulting in the infinite
|
||||
// Selector loop that refuses to shut down due to the dangling keys.
|
||||
synchronized (channel.interestOpsLock) {
|
||||
SelectionKey key = channel.socket.keyFor(selector);
|
||||
if (key != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user