From ce5993bc6f665fddb9f6b3c034cfe6e979de6825 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 25 Oct 2017 15:59:51 +1100 Subject: [PATCH] Issue #1920 Connect timeout Improved the ManagedSelector Dump Reverted CreateEndPoint to be a blocking task --- .../org/eclipse/jetty/io/ManagedSelector.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java index 3f1630c99da..0457c853305 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java @@ -37,6 +37,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; @@ -472,16 +473,33 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable if (selector != null && selector.isOpen()) { Set keys = selector.keys(); - _dumps.add(selector + " keys=" + keys.size()); + AtomicInteger cancelled = new AtomicInteger(); + AtomicInteger excepted = new AtomicInteger(); + + _dumps.add(new Object() + { + @Override + public String toString() + { + return String.format("%s keys=%d cancelled=%d excepted=%d",selector,keys.size(),cancelled.get(),excepted.get()); + } + }); + for (SelectionKey key : keys) { try { _dumps.add(String.format("SelectionKey@%x{i=%d}->%s", key.hashCode(), key.interestOps(), key.attachment())); } + catch (CancelledKeyException cke) + { + LOG.ignore(cke); + cancelled.incrementAndGet(); + } catch (Throwable x) { LOG.ignore(x); + excepted.incrementAndGet(); } } } @@ -604,7 +622,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable } } - private class CreateEndPoint extends NonBlockingAction implements Closeable + private class CreateEndPoint implements Runnable, Closeable { private final SelectableChannel channel; private final SelectionKey key;