Skip to content

Commit

Permalink
bugfix museumsvictoria#289 - not ready to call process.exitValue
Browse files Browse the repository at this point in the history
  • Loading branch information
justparking committed Mar 7, 2023
1 parent 96c81cf commit 0b2e958
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,9 @@ private void launchAndRead() throws Exception {

// fire the STOPPED handler if it had fully started previously
if (os != null)
Handler.tryHandle(_stoppedCallback, process.exitValue(), _callbackErrorHandler);
// .waitFor() is required instead of .exitValue() because it is possible (but rare) to get here
// with the process not fully dead and cleaned up yet
Handler.tryHandle(_stoppedCallback, process.waitFor(), _callbackErrorHandler);

// propagate exception only on unusual termination
if (_state == State.Started)
Expand Down Expand Up @@ -835,7 +837,7 @@ private void readTextLoop(Process process) throws Exception {
handleReceivedData(str);

// then fire the stopped event and pass through the exit value
Handler.tryHandle(_stoppedCallback, _process.waitFor(), _callbackErrorHandler);
Handler.tryHandle(_stoppedCallback, process.waitFor(), _callbackErrorHandler);
}
}

Expand Down Expand Up @@ -901,7 +903,7 @@ public void run() {
* No read-delimiters specified, so fire events as data segments arrive.
* (suppress was used with resource-free CountableInputStream)
*/
private void readUnboundedRawLoop(Process process) throws IOException {
private void readUnboundedRawLoop(Process process) throws Exception {
InputStream stdout = process.getInputStream();

@SuppressWarnings("resource")
Expand All @@ -926,8 +928,8 @@ private void readUnboundedRawLoop(Process process) throws IOException {
// the peer has gracefully closed down the connection or we're shutting down

if (!_shutdown) {
// then fire the disconnected callback
Handler.tryHandle(_stoppedCallback, _process.exitValue(), _callbackErrorHandler);
// then fire the stopped callback
Handler.tryHandle(_stoppedCallback, process.waitFor(), _callbackErrorHandler);
}
}

Expand Down

0 comments on commit 0b2e958

Please sign in to comment.