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.

Comments (0)

Files changed (1)

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();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.