gnodet-bot commented on code in PR #29804:
URL: https://github.com/apache/camel/pull/29804#discussion_r4566383066
##########
dsl/camel-jbang/camel-launcher/src/main/java/org/apache/camel/dsl/jbang/launcher/selfupdate/SelfUpdateCommand.java:
##########
@@ -368,10 +377,40 @@ private Integer runInstaller(String targetVersion) {
// pin-state file for this run. Set last so it can never be
dropped by the override block above.
pb.environment().put("CAMEL_INSTALL_SELF_UPDATE", "true");
Process process = pb.start();
- String output = new
String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
- int exit = process.waitFor();
- printer().print(output);
- return exit;
+ // Drain stdout in a separate thread to prevent the subprocess
from blocking on a full pipe buffer in
+ // the gap before waitFor() returns. Then wait with a timeout to
prevent an indefinitely stalled
+ // installer from hanging the CLI.
+ ExecutorService drainer = Executors.newSingleThreadExecutor(r -> {
+ Thread t = new Thread(r, "camel-self-update-drainer");
+ t.setDaemon(true);
+ return t;
+ });
+ Future<String> outputFuture = drainer
+ .submit(() -> new
String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
+ try {
+ boolean finished = process.waitFor(processWaitTimeoutSeconds,
TimeUnit.SECONDS);
+ if (!finished) {
+ // Kill grandchildren first (curl/wget etc.) before the
shell, so they release the pipe
+
process.descendants().forEach(ProcessHandle::destroyForcibly);
+ process.destroyForcibly();
+ printer().printErr("installer timed out after 5 minutes");
Review Comment:
The error message is hardcoded as `"5 minutes"` but the actual wait duration
is driven by `processWaitTimeoutSeconds` (default `5 * 60`). Tests already
override this field to 2 seconds, so the message would be wrong if the timeout
is ever adjusted.
```suggestion
printer().printErr("installer timed out after " +
processWaitTimeoutSeconds + " seconds");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]