From 7f052753051904f7a425a5d24460f02d79e3f1a0 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 27 Oct 2009 06:20:45 +0000 Subject: [PATCH] The thread that calls NioWorker.close() might not be in the selector loop --- .../org/jboss/netty/channel/socket/nio/NioWorker.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java index 821ea9151d..9c6b8ec589 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java @@ -22,7 +22,6 @@ import java.net.SocketAddress; import java.nio.channels.AsynchronousCloseException; import java.nio.channels.CancelledKeyException; import java.nio.channels.ClosedChannelException; -import java.nio.channels.ClosedSelectorException; import java.nio.channels.NotYetConnectedException; import java.nio.channels.ScatteringByteChannel; import java.nio.channels.SelectionKey; @@ -587,13 +586,15 @@ class NioWorker implements Runnable { // Otherwise the process will experience sudden spike // in the number of open files, with high chance of getting // the 'too many open files' error. - try { + if (Thread.currentThread() == worker.thread) { selector.selectNow(); if (worker.wakenUp.get()) { selector.wakeup(); } - } catch (ClosedSelectorException e) { - // Can happen - ignore. + } else { + if (worker.wakenUp.compareAndSet(false, true)) { + selector.wakeup(); + } } } }