Skip to content

Commit

Permalink
Fix edge case with output stream closing early.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Jan 1, 2025
1 parent 8f8d456 commit bbf000e
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<String> socketPort;

Expand All @@ -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);
}
}
Expand Down

0 comments on commit bbf000e

Please sign in to comment.