From bbf000e13dcb5938c868aa6e7323314ec28a73fa Mon Sep 17 00:00:00 2001 From: Luke Bemish Date: Tue, 31 Dec 2024 19:35:12 -0600 Subject: [PATCH] Fix edge case with output stream closing early. --- .../forkedtaskexecutor/ForkedTaskExecutor.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/dev/lukebemish/forkedtaskexecutor/ForkedTaskExecutor.java b/src/main/java/dev/lukebemish/forkedtaskexecutor/ForkedTaskExecutor.java index 73b8663..6dcd1b8 100644 --- a/src/main/java/dev/lukebemish/forkedtaskexecutor/ForkedTaskExecutor.java +++ b/src/main/java/dev/lukebemish/forkedtaskexecutor/ForkedTaskExecutor.java @@ -60,6 +60,10 @@ public ForkedTaskExecutor(ForkedTaskExecutorSpec spec) { System.err.println(line); } } catch (IOException e) { + if (ForkedTaskExecutor.this.listener.closed.get()) { + // The listener closed, possibly closing this stream as we were processing a line; this is fine + return; + } throw new UncheckedIOException(e); } }).start(); @@ -74,7 +78,7 @@ public ForkedTaskExecutor(ForkedTaskExecutorSpec spec) { } } - private static final class StreamWrapper extends Thread { + private final class StreamWrapper extends Thread { private final InputStream stream; private final CompletableFuture socketPort; @@ -97,6 +101,10 @@ public void run() { System.out.println(line); } } catch (IOException exception) { + if (ForkedTaskExecutor.this.listener.closed.get()) { + // The listener closed, possibly closing this stream as we were processing a line; this is fine + return; + } throw new UncheckedIOException(exception); } }