Skip to content
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

Concurrency Bug between isAlive() and exitValue() in ManagedProcess and/or in DefaultExecuteResultHandler #108

Closed
vorburger opened this issue May 13, 2023 · 2 comments
Assignees
Labels

Comments

@vorburger
Copy link
Owner

enola-dev/enola#163 may be due to a Concurrency Bug between isAlive() and exitValue() ?

In ManagedProcess#waitForExitMaxMsWithoutLog() there is currently this:

if (maxWaitUntilReturning != -1) {
    resultHandler.waitFor(maxWaitUntilReturning);
    checkResult();
    if (!isAlive()) {
        return exitValue();
    }
    return INVALID_EXITVALUE;
}

My original thinking was probably that because checkResult() does resultHandler.hasResult() this should be safe? But on 2nd thought, 10 years 😄 later, I wonder:

  • Firstly, why not just check for hasResult() (or, better, add a new hasExitValue()) instead of !isAlive()
  • secondly, if there could be a concurrency issue wherein the DefaultExecuteResultHandler x3 volatile fields hasResult and exitValue and exception are not set "atomically"... that could be written better.

Also, it's probably better to introduce separate new special values for INVALID_EXITVALUE instead of using that for several things would also make debug clearer. Or, probably better, just throw a new exception, in case of such clear inconsistent states - that INVALID_EXITVALUE is more confusing that really providing any useful feedback to a caller.

I'll raise a PR with some work around this - and see if it helps me to stop runing into enola-dev/enola#163 while using https://docs.enola.dev/use/execmd.

@mosesn (from #103) and @cardamon (from #96) and @duttonw FYI.

@vorburger vorburger added the bug label May 13, 2023
@vorburger vorburger self-assigned this May 13, 2023
@vorburger
Copy link
Owner Author

Oh wait I forgot DefaultExecuteResultHandler is actually from package org.apache.commons.exec and not mine...

... I will just replace it with a new AtomicExecuteResultHandler of our own in an upcoming PR...

@vorburger
Copy link
Owner Author

vorburger commented May 13, 2023

Closing this issue, hoping this will work better (or at least lead to clearer errors?) with #110 + #112.

I'll release this as 3.1.5 (maybe together with #45)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant