-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8303133: Update ProcessTools.startProcess(...) to exit early if process exit before linePredicate is printed. #12751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…s exit before linePredicate is printed.
👋 Welcome back lmesnik! A progress list of the required criteria for merging this PR into |
Webrevs
|
I fixed a typo in the bug's synopsis line so you'll need to update the PR's title. |
/issue JDK-8303133 |
@lmesnik This issue is referenced in the PR title - it will now be updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a number of issues with the changes. I think you have basically addressed the problem of waiting forever if no predicate line was forthcoming, but I think you have introduced a race with normal termination of the process.
boolean succeeded = Utils.waitForCondition(() -> { | ||
//Fail if process finished before printed expected string | ||
if (!p.isAlive()) { | ||
latch.countDown(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This countdown
serves no purpose. The latch is used to coordinate the current thread and the stream pumper thread: the current thread calls await
and the streamPumper calls countDown
. Here the current thread is not going to call await
and it doesn't need to countDown
to release itself.
if (!latch.await(Utils.adjustTimeout(timeout), unit)) { | ||
throw new TimeoutException(); | ||
// Every second check if process is still alive | ||
boolean succeeded = Utils.waitForCondition(() -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This use of waitForCondition
with a sleep time of zero confused me quite a bit. Now I realize that you are putting waitForCondition
into a potential busy-poll loop, but then you introduce the one-second timed await
as part of the condition, thus effectively checking the condition once a second. This seems somewhat convoluted compared to just using a sleep time of 1000ms and changing the await
to a call to getCount() > 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using await() is more effective than checking every second. However, might be it is not essential for multi-process synchronization.
//Fail if process finished before printed expected string | ||
if (!p.isAlive()) { | ||
latch.countDown(); | ||
throw new RuntimeException("Started process " + name + " is not alive."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. ???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 detecting 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");
}
}
this.process = ProcessTools.startProcess(name, processBuilder, waitfor); | ||
// Release when process is started | ||
latch.countDown(); | ||
String name = Thread.currentThread().getName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code passes the name of the ProcessRunnable
to startProcess
, not the name of the current thread. It is not obvious/apparent that they are the same. But if they are then it is cheaper to use name
than do a dynamic query on the current thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed, it is a mistake.
throw new RuntimeException("Started process " + name + " is not alive."); | ||
// Give some extra time for the StreamPumper to run after the process completed | ||
Thread.sleep(1000); | ||
if (latch.getCount() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we use > 0 here but != 0 above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let use > in all places
// 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 + " is not alive."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the message is not very informative - we expect the process to die, the problem is it died before giving the necessary output. Suggestion:
"Started process " + name + "terminated before producing the expected output"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems okay to me now. Thanks.
@lmesnik This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 36 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@dholmes-ora, Thank you for your comments. |
/integrate |
Going to push as commit 1fdaf25.
Your commit was automatically rebased without conflicts. |
We are seeing large numbers of failures after this change was integrated, so it will likely need to be backed out. |
The solution proposed by Stefan K
The startProcess() might wait forever for the expected line if the process exits (failed to start). It makes sense to just fail earlier in such cases.
The fix also move
'output = new OutputAnalyzer(this.process);'
in method xrun() to be able to try to print them in waitFor is failed/interrupted.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/12751/head:pull/12751
$ git checkout pull/12751
Update a local copy of the PR:
$ git checkout pull/12751
$ git pull https://git.openjdk.org/jdk pull/12751/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 12751
View PR using the GUI difftool:
$ git pr show -t 12751
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12751.diff