From 08e9e3ce67287b4784cd828df84283d601c55ede Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 8 Nov 2024 17:59:03 -0500 Subject: [PATCH] For whatever reason, `onBinary` is never called, so the client just hangs --- cli/src/main/java/hudson/cli/CLI.java | 11 ++++++----- test/src/test/java/hudson/cli/CLIActionTest.java | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cli/src/main/java/hudson/cli/CLI.java b/cli/src/main/java/hudson/cli/CLI.java index 7ce6a9d238fa..7835020c604a 100644 --- a/cli/src/main/java/hudson/cli/CLI.java +++ b/cli/src/main/java/hudson/cli/CLI.java @@ -54,7 +54,6 @@ import java.util.List; import java.util.Locale; import java.util.Properties; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicReference; @@ -367,14 +366,16 @@ public void close() throws IOException { ws.set(wsb.buildAsync(URI.create(url.replaceFirst("^http", "ws") + "cli/ws"), new WebSocket.Listener() { @Override public CompletionStage onBinary(WebSocket webSocket, ByteBuffer data, boolean last) { - var f = new CompletableFuture(); try { connection.handle(new DataInputStream(new ByteArrayInputStream(data.array()))); - f.complete(null); } catch (IOException x) { - f.completeExceptionally(x); + LOGGER.log(Level.WARNING, null, x); } - return f; + return null; + } + @Override + public void onError(WebSocket webSocket, Throwable error) { + LOGGER.log(Level.WARNING, null, error); } }).get()); connection.start(args); diff --git a/test/src/test/java/hudson/cli/CLIActionTest.java b/test/src/test/java/hudson/cli/CLIActionTest.java index f76584e6a531..53895fb1553c 100644 --- a/test/src/test/java/hudson/cli/CLIActionTest.java +++ b/test/src/test/java/hudson/cli/CLIActionTest.java @@ -158,7 +158,7 @@ public void encodingAndLocale() throws Exception { assertEquals(0, new Launcher.LocalLauncher(StreamTaskListener.fromStderr()).launch().cmds( "java", "-Dfile.encoding=ISO-8859-2", "-Duser.language=cs", "-Duser.country=CZ", "-jar", jar.getAbsolutePath(), "-s", j.getURL().toString()./* just checking */replaceFirst("/$", ""), "test-diagnostic"). - stdout(baos).stderr(System.err).join()); + stdout(new TeeOutputStream(baos, System.out)).stderr(System.err).join()); assertEquals("encoding=ISO-8859-2 locale=cs_CZ", baos.toString(Charset.forName("ISO-8859-2")).trim()); // TODO test that stdout/stderr are in expected encoding (not true of -remoting mode!) // -ssh mode does not pass client locale or encoding