Skip to content

Commit 16eccc1

Browse files
committed
AllLinesParser: Enable draining of stdout
If draining isn't enabled, the AllLinesParser and Script timeout, because noone is reading the full output of the process and so the process can't finish and will timeout. This was noticed while `drbdsetup events --now` was writing around 1200 lines into stdout and always hang in a timeout.
1 parent 6f3e4e6 commit 16eccc1

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

utils/src/main/java/com/cloud/utils/script/OutputInterpreter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public String interpret(BufferedReader reader) throws IOException {
137137
public String getLines() {
138138
return allLines;
139139
}
140+
141+
@Override
142+
public boolean drain() {
143+
return true;
144+
}
140145
}
141146

142147
public static class LineByLineOutputLogger extends OutputInterpreter {

utils/src/test/java/com/cloud/utils/ScriptTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ public String interpret(BufferedReader reader) throws IOException {
111111
Assert.assertNotNull(value);
112112
}
113113

114+
@Test
115+
public void executeWithOutputInterpreterAllLineReader() {
116+
Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
117+
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
118+
Script script = new Script("seq");
119+
script.add("-f");
120+
script.add("my text to test cloudstack %g");
121+
script.add("4096"); // AllLinesParser doesn't work with that amount of data
122+
String value = script.execute(parser);
123+
// it is a stack trace in this case as string
124+
Assert.assertNull(value);
125+
Assert.assertEquals(129965, parser.getLines().length());
126+
}
127+
114128
@Test
115129
public void runSimpleBashScriptNotExisting() {
116130
Assume.assumeTrue(SystemUtils.IS_OS_LINUX);

0 commit comments

Comments
 (0)