BIGTOP-950. race condition for output consumption in Shell code

Project: http://git-wip-us.apache.org/repos/asf/bigtop/repo
Commit: http://git-wip-us.apache.org/repos/asf/bigtop/commit/bc49df0b
Tree: http://git-wip-us.apache.org/repos/asf/bigtop/tree/bc49df0b
Diff: http://git-wip-us.apache.org/repos/asf/bigtop/diff/bc49df0b

Branch: refs/heads/master
Commit: bc49df0bf3ed71dbe7a8ded7857b6087d4df8fd0
Parents: bb2b739
Author: Roman Shaposhnik <[email protected]>
Authored: Tue Apr 30 17:08:26 2013 -0700
Committer: Roman Shaposhnik <[email protected]>
Committed: Tue Apr 30 17:16:44 2013 -0700

----------------------------------------------------------------------
 .../org/apache/bigtop/itest/shell/Shell.groovy     |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bigtop/blob/bc49df0b/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/shell/Shell.groovy
----------------------------------------------------------------------
diff --git 
a/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/shell/Shell.groovy
 
b/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/shell/Shell.groovy
index 4df3642..fbd85e3 100644
--- 
a/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/shell/Shell.groovy
+++ 
b/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/shell/Shell.groovy
@@ -83,13 +83,14 @@ class Shell {
     }
     ByteArrayOutputStream outStream = new ByteArrayOutputStream(4096)
     ByteArrayOutputStream errStream = new ByteArrayOutputStream(4096)
-    Thread.start {
-      proc.consumeProcessOutput(outStream, errStream)
-    }
     if (timeout >= 0) {
+      // WARNING: there's a potential race condition bellow
+      //          essentially what we really need here is
+      //          proc.waitForOrKillProcessOutput(outStream, errStream)
+      proc.consumeProcessOutput(outStream, errStream)
       proc.waitForOrKill(timeout)
     } else {
-      proc.waitFor()
+      proc.waitForProcessOutput(outStream, errStream)
     }
 
     // Possibly a bug in String.split as it generates a 1-element array on an

Reply via email to