From 4b8b8b3ba03f122eebf75e2fcb9f4611568bff33 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 28 Jan 2011 01:12:48 +0000 Subject: [PATCH] 335641 Sweep for Windows selectKey.interestOps!=endp.interestOps for undispatched end points This is a temporary fix until we get to the root of the problem git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2702 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../jetty/io/nio/SelectChannelEndPoint.java | 37 ++++++++++++------- .../eclipse/jetty/io/nio/SelectorManager.java | 26 ++++++++++--- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index b9a0085b0df..8641ca15ad8 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1,6 +1,7 @@ jetty-7.3.1-SNAPSHOT + 331803 Update XML configuration files to use proper arguments for startup command in examples + 335361 Fixed 'jetty.sh check' to show current PID when JETTY_PID env. variable is set + + 335641 Sweep for Windows selectKey.interestOps!=endp.interestOps for undispatched end points jetty-7.3.0.v20112401 24 January 2011 + JETTY-1259 NullPointerException in JDBCSessionIdManager when invalidating session (further update) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java index 293916497bc..a52f92d227a 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @@ -146,7 +146,8 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo this.notifyAll(); // we are not interested in further selecting - _key.interestOps(0); + if (_dispatched) + _key.interestOps(0); return; } @@ -158,7 +159,6 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo return; } - // Remove writeable op if ((_key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE && (_key.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) { @@ -168,18 +168,12 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo _writable = true; // Once writable is in ops, only removed with dispatch. } - if (_selectSet.getManager().isDeferringInterestedOps0()) + // Dispatch if we are not already + if (!_dispatched) { - if (_dispatched) + dispatch(); + if (_dispatched && !_selectSet.getManager().isDeferringInterestedOps0()) _key.interestOps(0); - else - dispatch(); - } - else - { - _key.interestOps(0); - if (!_dispatched) - dispatch(); } } } @@ -298,6 +292,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo { synchronized (this) { + // Ready if not dispatched and not suspended return !(_dispatched || getConnection().isSuspended()); } } @@ -612,6 +607,20 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo _maxIdleTime=timeMs; } - - + /* ------------------------------------------------------------ */ + /** + * This looks for undispatched endpoints that have key.interestOps!=endp.interestOps + * @TODO find out the root cause of this and delete this method. + */ + public void checkWindowsBug(SelectionKey key) + { + synchronized (this) + { + if (!_dispatched && key.interestOps()!=_interestOps) + { + Log.warn("Windows NIO bug? "+key.interestOps()+"!="+_interestOps+" for "+this); + doUpdateKey(); + } + } + } } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java index 3e15ff5817a..08b3fd2bc6d 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/nio/SelectorManager.java @@ -23,8 +23,6 @@ import java.nio.channels.SocketChannel; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import org.eclipse.jetty.io.ConnectedEndPoint; import org.eclipse.jetty.io.Connection; @@ -45,6 +43,9 @@ import org.eclipse.jetty.util.thread.Timeout.Task; */ public abstract class SelectorManager extends AbstractLifeCycle { + // TODO remove this + private final static boolean __onWindows = System.getProperty("os.name").toLowerCase().indexOf("windows")>=0; + // TODO Tune these by approx system speed. private static final int __JVMBUG_THRESHHOLD=Integer.getInteger("org.eclipse.jetty.io.nio.JVMBUG_THRESHHOLD",0).intValue(); private static final int __MONITOR_PERIOD=Integer.getInteger("org.eclipse.jetty.io.nio.MONITOR_PERIOD",1000).intValue(); @@ -59,7 +60,7 @@ public abstract class SelectorManager extends AbstractLifeCycle private SelectSet[] _selectSet; private int _selectSets=1; private volatile int _set; - private boolean _deferringInterestedOps0; + private boolean _deferringInterestedOps0=true; /* ------------------------------------------------------------ */ /** @@ -570,6 +571,20 @@ public abstract class SelectorManager extends AbstractLifeCycle } } }); + + // TODO find root cause and remove this + // Check for windows bug + // This looks for undispatched endpoints that have key.interestOps!=endp.interestOps + if (__onWindows) + { + for (SelectionKey key: selector.keys()) + { + if (key.isValid() && key.attachment() instanceof SelectChannelEndPoint) + { + ((SelectChannelEndPoint)key.attachment()).checkWindowsBug(key); + } + } + } } } catch (CancelledKeyException e) @@ -855,7 +870,6 @@ public abstract class SelectorManager extends AbstractLifeCycle } } } - } /* ------------------------------------------------------------ */ @@ -879,9 +893,9 @@ public abstract class SelectorManager extends AbstractLifeCycle } /* ------------------------------------------------------------ */ - public void setDeferringInterestedOps0(boolean defferringInterestedOps0) + public void setDeferringInterestedOps0(boolean deferringInterestedOps0) { - _deferringInterestedOps0 = defferringInterestedOps0; + _deferringInterestedOps0 = deferringInterestedOps0; } }