From ddc63066fcf66e6a2b0541e02e3b5246571ac9ae Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 16 Jan 2017 19:05:09 +0100 Subject: [PATCH 1/2] Fixes #1259 - HostnameVerificationTest.simpleGetWithHostnameVerificationEnabledTest is broken. When a fill() triggered by a flush() throws, now the write flusher is failed rather than completed. This ensures that both the read and the write side see the same exception, rather than the write side seeing a ClosedChannelException. --- .../client/HostnameVerificationTest.java | 13 ++++++---- .../eclipse/jetty/io/ssl/SslConnection.java | 26 ++++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HostnameVerificationTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HostnameVerificationTest.java index e4b81b3ec3f..8552b1985e3 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HostnameVerificationTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HostnameVerificationTest.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.client; import java.io.IOException; -import java.nio.channels.ClosedChannelException; import java.security.cert.CertificateException; import java.util.concurrent.ExecutionException; @@ -48,13 +47,17 @@ import org.junit.Test; public class HostnameVerificationTest { private SslContextFactory clientSslContextFactory = new SslContextFactory(); - private Server server = new Server(); + private Server server; private HttpClient client; private NetworkConnector connector; @Before public void setUp() throws Exception { + QueuedThreadPool serverThreads = new QueuedThreadPool(); + serverThreads.setName("server"); + server = new Server(serverThreads); + SslContextFactory serverSslContextFactory = new SslContextFactory(); serverSslContextFactory.setKeyStorePath("src/test/resources/keystore.jks"); serverSslContextFactory.setKeyStorePassword("storepwd"); @@ -75,10 +78,10 @@ public class HostnameVerificationTest clientSslContextFactory.setKeyStorePath("src/test/resources/keystore.jks"); clientSslContextFactory.setKeyStorePassword("storepwd"); - QueuedThreadPool executor = new QueuedThreadPool(); - executor.setName(executor.getName() + "-client"); + QueuedThreadPool clientThreads = new QueuedThreadPool(); + clientThreads.setName("client"); client = new HttpClient(clientSslContextFactory); - client.setExecutor(executor); + client.setExecutor(clientThreads); client.start(); } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java index 469d89f14f9..fd95a5b5267 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java @@ -514,6 +514,7 @@ public class SslConnection extends AbstractConnection { synchronized (this) { + Throwable failure = null; try { // Do we already have some decrypted data? @@ -708,6 +709,7 @@ public class SslConnection extends AbstractConnection catch (SSLHandshakeException x) { notifyHandshakeFailed(_sslEngine, x); + failure = x; throw x; } catch (SSLException x) @@ -717,6 +719,12 @@ public class SslConnection extends AbstractConnection x = (SSLException)new SSLHandshakeException(x.getMessage()).initCause(x); notifyHandshakeFailed(_sslEngine, x); } + failure = x; + throw x; + } + catch (Throwable x) + { + failure = x; throw x; } finally @@ -725,7 +733,7 @@ public class SslConnection extends AbstractConnection if (_flushRequiresFillToProgress) { _flushRequiresFillToProgress = false; - getExecutor().execute(_runCompletWrite); + getExecutor().execute(failure == null ? _runCompletWrite : new FailFlusher(failure)); } if (_encryptedInput != null && !_encryptedInput.hasRemaining()) @@ -1080,5 +1088,21 @@ public class SslConnection extends AbstractConnection { return super.toString()+"->"+getEndPoint().toString(); } + + private class FailFlusher implements Runnable + { + private final Throwable failure; + + private FailFlusher(Throwable failure) + { + this.failure = failure; + } + + @Override + public void run() + { + getWriteFlusher().onFail(failure); + } + } } } From 76ba287f6c9e83176827b23070403e41a639665c Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 16 Jan 2017 19:09:26 +0100 Subject: [PATCH 2/2] Fixed JUnit JavaDocs URL. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a8a92edd622..2d63e7bf0b0 100644 --- a/pom.xml +++ b/pom.xml @@ -374,7 +374,7 @@ http://docs.oracle.com/javase/8/docs/api/ http://docs.oracle.com/javaee/7/api/ - http://junit.org/javadoc/latest/ + http://junit.org/junit4/javadoc/latest/ http://download.eclipse.org/jetty/stable-9/apidocs/