From 37ab716bc5f4cee76d52b22312e6de645dce7e6c Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 28 Feb 2019 17:32:38 +1100 Subject: [PATCH] Issue #3170 - fail the CompletableFuture if onOpen throws Signed-off-by: Lachlan Roberts --- .../jetty/websocket/core/internal/WebSocketChannel.java | 7 +++++++ .../jetty/websocket/core/proxy/WebSocketProxyTest.java | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java index cb36e8f15f2..4e61823ad05 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java @@ -440,6 +440,13 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio catch (Throwable t) { openCallback.failed(t); + + /* + This is double handling of the exception but we need to do this because we have two separate + mechanisms for returning the CoreSession, onOpen and the CompletableFuture and both the onOpen callback + and the CompletableFuture require the exception. + */ + throw new RuntimeException(t); } } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java index e9411c341c5..b68f0db76b1 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/proxy/WebSocketProxyTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.URI; import java.time.Duration; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -57,6 +58,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; public class WebSocketProxyTest { @@ -231,7 +233,8 @@ public class WebSocketProxyTest try (StacklessLogging stacklessLogging = new StacklessLogging(WebSocketChannel.class)) { CompletableFuture response = _client.connect(clientHandler, new URI("ws://localhost:8080/proxy/")); - response.get(5, TimeUnit.SECONDS); + Exception e = assertThrows(ExecutionException.class, ()->response.get(5, TimeUnit.SECONDS)); + assertThat(e.getMessage(), containsString("simulated client onOpen error")); clientHandler.awaitClose(); serverFrameHandler.awaitClose(); awaitProxyClose(proxyClientSide, proxyServerSide);