Skip to content

Commit 45a9cb6

Browse files
authored
Merge pull request #34072 from KyleAure/bb308561-feature-list-generate-output
debug: FeatureList timeouts
2 parents 5955447 + a442e52 commit 45a9cb6

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

dev/fattest.simplicity/src/componenttest/depchain/FeatureList.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2022 IBM Corporation and others.
2+
* Copyright (c) 2017, 2026 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
@@ -12,10 +12,15 @@
1212
*******************************************************************************/
1313
package componenttest.depchain;
1414

15+
import java.io.BufferedReader;
1516
import java.io.File;
1617
import java.io.IOException;
17-
import java.util.Scanner;
18+
import java.io.InputStreamReader;
19+
import java.nio.charset.StandardCharsets;
20+
import java.util.concurrent.Executors;
21+
import java.util.concurrent.Future;
1822
import java.util.concurrent.TimeUnit;
23+
import java.util.stream.Collectors;
1924

2025
import com.ibm.websphere.simplicity.log.Log;
2126

@@ -33,7 +38,7 @@ public class FeatureList {
3338

3439
@SuppressWarnings("resource")
3540
public static synchronized File get(LibertyServer server) throws Exception {
36-
final String m = "createFeatureList";
41+
final String m = "get";
3742

3843
featureList = new File(server.getUserDir() + "/servers", FAT_FEATURE_LIST);
3944
if (featureList.exists())
@@ -45,23 +50,38 @@ public static synchronized File get(LibertyServer server) throws Exception {
4550
Process featureListProc = new ProcessBuilder("java", "-jar", featureListJar, featureList.getAbsolutePath())
4651
.redirectErrorStream(true)
4752
.start();
53+
54+
// Create a thread to capture the output of the process (stdout + stderr)
55+
Future<String> output = Executors.newSingleThreadExecutor().submit(() -> {
56+
return new BufferedReader(new InputStreamReader(featureListProc.getInputStream(), StandardCharsets.UTF_8))
57+
.lines()
58+
.collect(Collectors.joining(System.lineSeparator()));
59+
});
60+
4861
boolean completed = featureListProc.waitFor(TIMEOUT_MINUTES, TimeUnit.MINUTES);
4962
if (!completed) {
50-
Exception e = new Exception("Generating " + FAT_FEATURE_LIST + " timed out after " + TIMEOUT_MINUTES + " minutes. Aborting process.");
51-
Log.error(c, m, e);
63+
// Destroy the process (still capturing output)
5264
featureListProc.destroyForcibly();
5365
featureListProc.waitFor();
66+
67+
//Output error
68+
Exception e = new Exception("Generating " + FAT_FEATURE_LIST + " timed out after "
69+
+ TIMEOUT_MINUTES + " minutes. Aborting process." + System.lineSeparator()
70+
+ output.get());
71+
Log.error(c, m, e);
72+
5473
reset();
5574
throw e;
5675
}
76+
5777
int rc = featureListProc.exitValue();
5878
if (rc != 0) {
59-
String cmdOutput;
60-
try (Scanner s = new Scanner(featureListProc.getInputStream()).useDelimiter("\\A")) {
61-
cmdOutput = s.hasNext() ? s.next() : "";
62-
}
63-
Exception e = new Exception("Process failed with rc=" + rc + " for " + featureList.getAbsolutePath() + " generation:\n" + cmdOutput);
79+
//Output error
80+
Exception e = new Exception("Process failed with rc=" + rc + " for " + featureList.getAbsolutePath()
81+
+ " generation:" + System.lineSeparator()
82+
+ output.get());
6483
Log.error(c, m, e);
84+
6585
reset();
6686
throw e;
6787
}

0 commit comments

Comments
 (0)