From 0b41841e0a6be0d248d08ee93f21832e5ca988e1 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 2 Feb 2011 20:09:47 +0000 Subject: [PATCH] 335641 added a sweep to check for error git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2728 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../jetty/io/nio/SelectChannelEndPoint.java | 21 +++++++++++++++++++ .../eclipse/jetty/io/nio/SelectorManager.java | 14 +++++++++++-- .../org/eclipse/jetty/server/StressTest.java | 5 +++-- .../org/eclipse/jetty/start/Classpath.java | 6 +----- 4 files changed, 37 insertions(+), 9 deletions(-) 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 a54bad86e4a..921947713a7 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 @@ -51,6 +51,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo private boolean _writeBlocked; private boolean _open; private volatile long _idleTimestamp; + private boolean _changing=false; /* ------------------------------------------------------------ */ public SelectChannelEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key, int maxIdleTime) @@ -423,6 +424,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo if(_interestOps == ops && getChannel().isOpen()) return; + _changing=true; } _selectSet.addChange(this); _selectSet.wakeup(); @@ -436,6 +438,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo { synchronized (this) { + _changing=false; if (getChannel().isOpen()) { if (_interestOps>0) @@ -612,4 +615,22 @@ 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 checkKey(SelectionKey key) + { + synchronized (this) + { + if (!_changing && !_dispatched && key.interestOps()!=_interestOps) + { + Log.warn("NIO InterestOps mismatch "+key.interestOps()+"!="+_interestOps+" for "+this); + updateKey(); + } + } + } + } 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 df396e15610..e2c33e7599e 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 @@ -22,7 +22,6 @@ import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -562,6 +561,16 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa } } }); + + // TODO find root cause and remove this + // This looks for undispatched endpoints that have key.interestOps!=endp.interestOps + for (SelectionKey key: selector.keys()) + { + if (key.isValid() && key.attachment() instanceof SelectChannelEndPoint) + { + ((SelectChannelEndPoint)key.attachment()).checkKey(key); + } + } } } catch (CancelledKeyException e) @@ -881,7 +890,8 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa } AggregateLifeCycle.dump(out,indent,dump); } - + + /* ------------------------------------------------------------ */ public void dumpKeyState(List dumpto) { Selector selector=_selector; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java index 08faccdf047..9b1ea960a40 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java @@ -152,6 +152,7 @@ public class StressTest { final int id=i; final String name = "T"+i; + Thread.sleep(_random.nextInt(100)); threads[i]=new Thread() { @Override @@ -305,8 +306,8 @@ public class StressTest { _loops[thread].set(i); doPaths(thread,name+"-"+i,persistent); - Thread.sleep(1+_random.nextInt(10)*_random.nextInt(10)); - Thread.sleep(10); + Thread.sleep(1+_random.nextInt(20)*_random.nextInt(20)); + Thread.sleep(20); } _loops[thread].set(loops); } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java index a4f60b81a16..0e83c27b7ba 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Classpath.java @@ -20,7 +20,6 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.util.Arrays; import java.util.StringTokenizer; import java.util.Vector; @@ -145,18 +144,15 @@ public class Classpath { private static class Loader extends URLClassLoader { - String name; - Loader(URL[] urls, ClassLoader parent) { super(urls, parent); - name = "StartLoader"+Arrays.asList(urls); } @Override public String toString() { - return name; + return "startJarLoader@"+Long.toHexString(hashCode()); } }