486930 - Selector does not correctly handle rejected execution exception
Improved comments and unit test
diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java
index de4a5d2..c6753c5 100644
--- a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java
+++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java
@@ -777,11 +777,45 @@
}.start();
}
+ // unblock the handling
latch.countDown();
+
+ // wait for all clients to complete or fail
closed.await();
+
+ // assert some clients must have been rejected
Assert.assertThat(rejections.get(),Matchers.greaterThan(0));
+ // but not all of them
Assert.assertThat(rejections.get(),Matchers.lessThan(10));
+ // none should have timed out
Assert.assertThat(timeout.get(),Matchers.equalTo(0));
- Assert.assertThat(echoed.get(),Matchers.equalTo(10-rejections.get()));
+ // and the rest should have worked
+ Assert.assertThat(echoed.get(),Matchers.equalTo(10-rejections.get()));
+
+ // and the selector is still working for new requests
+ try(Socket client = newClient();)
+ {
+ client.setSoTimeout(5000);
+
+ SocketChannel server = _connector.accept();
+ server.configureBlocking(false);
+
+ _manager.accept(server);
+
+ // Write client to server
+ client.getOutputStream().write("HelloWorld".getBytes(StandardCharsets.UTF_8));
+ client.getOutputStream().flush();
+ client.shutdownOutput();
+
+ // Verify echo server to client
+ for (char c : "HelloWorld".toCharArray())
+ {
+ int b = client.getInputStream().read();
+ assertTrue(b > 0);
+ assertEquals(c, (char)b);
+ }
+ assertEquals(-1,client.getInputStream().read());
+ }
+
}
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ExecuteProduceConsume.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ExecuteProduceConsume.java
index c3436ad..4643775 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ExecuteProduceConsume.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ExecuteProduceConsume.java
@@ -147,6 +147,7 @@
}
catch(Throwable e)
{
+ // just warn if lowresources execute fails and keep producing
LOG.warn(e);
}
}
@@ -218,7 +219,7 @@
}
catch(RejectedExecutionException e)
{
- // If we cannot execute, the close or discard the task and keep producing
+ // If we cannot execute, then discard/reject the task and keep producing
LOG.debug(e);
LOG.warn("RejectedExecution {}",task);
try
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ProduceExecuteConsume.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ProduceExecuteConsume.java
index 6e7c95e..9310c05 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ProduceExecuteConsume.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/strategy/ProduceExecuteConsume.java
@@ -62,7 +62,7 @@
}
catch(RejectedExecutionException e)
{
- // Close or discard tasks that cannot be executed
+ // Discard/reject tasks that cannot be executed
if (task instanceof Rejectable)
{
try