Skip to content

CommandLineUtils: ensure all pumpers are waited on in try-finally - #399

Merged
elharo merged 1 commit into
masterfrom
fix/commandlineutils-inputfeeder-cleanup
Aug 3, 2026
Merged

elharo merged 1 commit into
masterfrom
fix/commandlineutils-inputfeeder-cleanup

Conversation

@elharo

@elharo elharo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

In CommandLineUtils.call(), waitUntilDone() was called on inputFeeder, outputPumper, and errorPumper sequentially without try-finally (lines 298-303 of the original). If an earlier call threw (e.g., InterruptedException), the remaining pumpers were never waited on, leaving their threads potentially running.

The commented-out code just above (lines 277-297) shows the original author intended a try-finally chain but never enabled it.

Fix: Replaced the sequential calls and the dead commented block with a proper try-finally chain ensuring all three pumpers are waited on regardless of exceptions from earlier ones.

Fixes #398

@elharo
elharo requested a review from cstamas July 1, 2026 14:18
@slachiewicz slachiewicz added the bug Something isn't working label Jul 2, 2026
@elharo
elharo requested a review from desruisseaux August 1, 2026 16:31
Comment on lines +277 to +286
try {
if (inputFeeder != null) {
inputFeeder.waitUntilDone();
}
} finally {
try {
outputPumper.waitUntilDone();
} finally {
errorPumper.waitUntilDone();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works, but if more than one exception is thrown, we see only the last one. It would be possible to keep all of them with catch (Throwable e) and Throwable.addSuppressed(e) calls, but that would make the code more complex (I'm not sure it would be worth). Alternatively, this exception handling could be made easier if the pumpers implement AutoCloseable.

I'm not really suggesting a change. I'm not against deciding that it is not worth to keep all exceptions. Just submitting for your consideration and letting you decide.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, but I think I;m going to leave that for a future PR

@elharo
elharo merged commit 0c94846 into master Aug 3, 2026
16 checks passed
@elharo
elharo deleted the fix/commandlineutils-inputfeeder-cleanup branch August 3, 2026 10:38
@github-actions github-actions Bot added this to the 3.5.0 milestone Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CommandLineUtils.call() does not ensure all pumpers are waited on

3 participants