diff --git a/sjsonnet/client/src/sjsonnet/client/SjsonnetClientMain.java b/sjsonnet/client/src/sjsonnet/client/SjsonnetClientMain.java index fd422868..2867a21e 100644 --- a/sjsonnet/client/src/sjsonnet/client/SjsonnetClientMain.java +++ b/sjsonnet/client/src/sjsonnet/client/SjsonnetClientMain.java @@ -131,6 +131,13 @@ public static int run(String lockBase, locks.serverLock.await(); + // The server closes its end of the socket before releasing serverLock, + // so the output pumper will see EOF. Wait for it to finish so that all + // output is fully written to stdout/stderr before we exit. Without this + // join, System.exit() kills the daemon thread mid-pump, which can result + // in empty or truncated output (flaky test: secondInvocationReusesServer). + outThread.join(5_000); + try { String content = Files.readString(Path.of(lockBase, "exitCode"), StandardCharsets.UTF_8); return Integer.parseInt(content.trim());