Skip to content

Conversation

@andy-goryachev-oracle
Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle commented Apr 10, 2025

The code should not set the Task.state value to CANCELLED if the said task is already SUCCEEDED or FAILED.

This is a product bug.

Added @RepeatedTest(50) to the tests that used to fail intermittently - this made the test failed more reliably without the fix.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8088343: Race condition in javafx.concurrent.Task::cancel (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1769/head:pull/1769
$ git checkout pull/1769

Update a local copy of the PR:
$ git checkout pull/1769
$ git pull https://git.openjdk.org/jfx.git pull/1769/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1769

View PR using the GUI difftool:
$ git pr show -t 1769

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1769.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 10, 2025

👋 Welcome back angorya! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Apr 10, 2025

@andy-goryachev-oracle 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:

8088343: Race condition in javafx.concurrent.Task::cancel

Reviewed-by: kcr, arapte

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 9 new commits pushed to the master branch:

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 master branch, type /integrate in a new comment.

@andy-goryachev-oracle andy-goryachev-oracle marked this pull request as ready for review April 10, 2025 21:31
@openjdk openjdk bot added the rfr Ready for review label Apr 10, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 10, 2025

Webrevs

@kevinrushforth
Copy link
Member

Reviewers: @kevinrushforth @arapte

/reviewers 2

@openjdk
Copy link

openjdk bot commented Apr 10, 2025

@kevinrushforth
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@kevinrushforth kevinrushforth self-requested a review April 11, 2025 16:08
Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding the case where we transition from FAILED or SUCCEEDED to CANCELLED is good, and should fix the test failures (although I'll do some additional testing), but I can't help wondering if underlying problem is something else. The question I have is: how do we get into a state where Worker.State of the Task one of the completion states (FAILED or SUCCEEDED), whereas the parent FutureTask is not completed, and so enters a canceled state. You can see this by instrumenting the code and calling super.isCancelled().

I wonder if the custom service created by TestServiceFactory is causing, or contributing to, the problem?

Comment on lines +1019 to +1021
switch (getState()) {
case FAILED:
case SUCCEEDED:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding transitioning from a one of the completion states to canceled is a good thing. My question, though is: how did we get here? Is this masking some other problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the variations in the test timing uncovered this issue. I don't think it's a problem with the execution of the task, but rather with the reporting of its final state.

break;
}
});
return rv.get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ineffective since you don't wait for the runLater to execute (and waiting could lead to deadlock, so I wouldn't recommend that). I don't think there is anything better than unconditionally returning flag when not running on the FX app thread. That's what the current code does (and is what your proposed fix will do most of the time).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!

In this particular case, returning true from cancel() when state will not be changed is acceptable.

@andy-goryachev-oracle andy-goryachev-oracle changed the title 8088343: Intermittent unit test failure in javafx.concurrent.ServiceLifecycleTest 8088343: Race condition in javafx.concurrent.Task::cancel Apr 21, 2025
Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I instrumented the code and after a few test runs was able to spot a couple cases where this would have failed without the fix.

@andy-goryachev-oracle
Copy link
Contributor Author

@arapte or @Ziad-Mid : could one of you be the second reviewer?

Copy link
Member

@arapte arapte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM... Could observe test failure without this change.

@openjdk openjdk bot added the ready Ready to be integrated label Apr 24, 2025
@andy-goryachev-oracle
Copy link
Contributor Author

Thank you Kevin and Ambarish!
/integrate

@openjdk
Copy link

openjdk bot commented Apr 24, 2025

Going to push as commit 48240da.
Since your change was applied there have been 11 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 24, 2025
@openjdk openjdk bot closed this Apr 24, 2025
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Apr 24, 2025
@openjdk
Copy link

openjdk bot commented Apr 24, 2025

@andy-goryachev-oracle Pushed as commit 48240da.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@andy-goryachev-oracle andy-goryachev-oracle deleted the 8088343.lifecycle branch April 24, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants