Commits

Michael Heemskerk committed ed4c58d

Fix to ensure that the ouput and error pumps get a chance to finish even if the process has already terminated.

  • Participants
  • Parent commits ca348aa

Comments (0)

Files changed (1)

File src/main/java/com/atlassian/utils/process/ExternalProcessImpl.java

         this.useWindowsEncodingWorkaround = useWindowsEncodingWorkaround;
     }
 
-    private boolean arePumpsRunning() {
-        return (outputPump != null && outputPump.isRunning()) ||
-                (errorPump != null && errorPump.isRunning()) ||
-                (inputPump != null && inputPump.isRunning());
+    private boolean areOutputPumpsRunning() {
+        return (outputPump != null && outputPump.isRunning()) || (errorPump != null && errorPump.isRunning());
     }
 
     /**
             try {
                 do {
                     long checkTime = getTimeoutTime();
+
+                    // block on the output pumps even when the process has already finished.
+                    // this gives the output pumps the chance to finish processing any output
+                    // still stuck in buffers
                     awaitPump(outputPump, checkTime);
                     awaitPump(errorPump, checkTime);
+
+                    // don't block on the input pump when the process has already finished
                     awaitPumpOrProcess(inputPump, checkTime);
-                } while (!isTimedOut() && isAlive() && arePumpsRunning() && !Thread.currentThread().isInterrupted());
+                } while (!isTimedOut() && areOutputPumpsRunning() && !Thread.currentThread().isInterrupted());
             } finally {
                 if (Thread.currentThread().isInterrupted()) {
                     cancel();
                 awaitPump(errorPump, endTime);
                 awaitPumpOrProcess(inputPump, endTime);
             } finally {
-                if (!arePumpsRunning() || !isAlive()) {
+                if (!areOutputPumpsRunning() || !isAlive()) {
                     // process finished
                     finished = true;
                     int exitCode = wrapUpProcess();