Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333742

ProcessImpl and ProcessHandleImpl may mishandle processes that exit with code 259

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 9, 23
    • core-libs
    • None
    • b02
    • windows

      In a few places we use the exit code STILL_ACTIVE (259) to determine that the process is still running. This may lead to incorrect behavior if the process in question actually exits with that exit code.

      Example of incorrect behavior:
              ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", "exit 259");
              Process p = pb.start();
              CompletableFuture<Process> processCompletableFuture = p.onExit();

      The completable future never completes, even though the process exits immediately. Instead, the code leaves a thread busy-looping in Java_java_lang_ProcessHandleImpl_waitForProcessExit0 native method.

      The more reliable way to determine if the process exited involves checking the return value of WaitForSingleObject / WaitForMultipleObjects waiting on the process handle. Of course, if GetExitCodeProcess returns a value other than STILL_ACTIVE, we can safely assume that the process is dead.

            djelinski Daniel Jelinski
            djelinski Daniel Jelinski
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: