RFR: 8303133: Update ProcessTools.startProcess(...) to exit early if process exit before linePredicate is printed. [v2]

David Holmes dholmes at openjdk.org
Mon Feb 27 21:58:34 UTC 2023


On Mon, 27 Feb 2023 17:55:40 GMT, Leonid Mesnik <lmesnik at openjdk.org> wrote:

>> test/lib/jdk/test/lib/process/ProcessTools.java line 224:
>> 
>>> 222:                     if (!p.isAlive()) {
>>> 223:                         latch.countDown();
>>> 224:                         throw new RuntimeException("Started process " + name + " is not alive.");
>> 
>> This seems problematic. The process has terminated but you don't know why - it may have completed normally and produced all the output such that the `await` below would return immediately with `true`, but you are now going to throw an exception. ???
>
> Thanks! You are right, we need to check first if the line has been printed.
> However, there is an interesting question the process can exit before streams are read and the latch is set to zero. The documentation says that linePredicate should detect if the process is warmed-up. So it is not expected that it should exit right after the start.

Yes there remains a race, if the process exits but the streamPumper has not yet had the chance to call `countDown` then we would again throw the exception. Perhaps all we can do is give a little extra time after decting a dead process?

if (!p.isAlive()) {
  if (latch.getCount() > 0) {
    // Give some extra time for the StreamPumper to run after the process completed
   Thread.sleep(1000); 
   if (latch.getCount() > 0) {
    throw new RuntimeException("Started process " + name + " but it terminated without the expected output");
  }
}

-------------

PR: https://git.openjdk.org/jdk/pull/12751


More information about the core-libs-dev mailing list