diff --git a/vaadin-dev-server/src/main/java/com/vaadin/base/devserver/viteproxy/ViteWebsocketConnection.java b/vaadin-dev-server/src/main/java/com/vaadin/base/devserver/viteproxy/ViteWebsocketConnection.java index 3b14308ced6..cf38b3251cf 100644 --- a/vaadin-dev-server/src/main/java/com/vaadin/base/devserver/viteproxy/ViteWebsocketConnection.java +++ b/vaadin-dev-server/src/main/java/com/vaadin/base/devserver/viteproxy/ViteWebsocketConnection.java @@ -42,7 +42,7 @@ public class ViteWebsocketConnection implements Listener { private final Consumer onMessage; private final Runnable onClose; - private final CompletableFuture clientWebsocket; + private final CompletableFuture clientWebsocket = new CompletableFuture<>(); private final List parts = new ArrayList<>(); private static Logger getLogger() { @@ -72,15 +72,20 @@ public ViteWebsocketConnection(int port, String path, String subProtocol, this.onClose = onClose; String wsHost = ViteHandler.DEV_SERVER_HOST.replace("http://", "ws://"); URI uri = URI.create(wsHost + ":" + port + path); - clientWebsocket = HttpClient.newHttpClient().newWebSocketBuilder() + HttpClient.newHttpClient().newWebSocketBuilder() .subprotocols(subProtocol).buildAsync(uri, this) .whenComplete(((webSocket, failure) -> { if (failure == null) { getLogger().debug( "Connection to {} using the {} protocol established", uri, webSocket.getSubprotocol()); + if (clientWebsocket.complete(webSocket)) { + getLogger().trace( + "Websocket future completed in client build completion"); + } } else { getLogger().debug("Failed to connect to {}", uri); + clientWebsocket.completeExceptionally(failure); onConnectionFailure.accept(failure); } })); @@ -90,6 +95,9 @@ public ViteWebsocketConnection(int port, String path, String subProtocol, public void onOpen(WebSocket webSocket) { getLogger().debug("Connected using the {} protocol", webSocket.getSubprotocol()); + if (clientWebsocket.complete(webSocket)) { + getLogger().trace("Websocket future completed in onOpen"); + } Listener.super.onOpen(webSocket); }