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

8311867: StructuredTaskScope.shutdown does not interrupt newly started threads #14833

Closed
wants to merge 1 commit into from

Conversation

AlanBateman
Copy link
Contributor

@AlanBateman AlanBateman commented Jul 11, 2023

StructuredTaskScope.shutdown can sometimes not interrupt the thread for a newly forked subtask, leading to join blocking until subtask completes. The "hang" can be duplicated with a stress test that shuts down the scope while a long running subtask is being forked. The bug is in the underlying thread flock code where it filters the threads to just the live threads and so filters out new/unstarted threads, that filtering was left over from some refactoring in the loom repo a long time ago and should have been removed.


Progress

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

Issue

  • JDK-8311867: StructuredTaskScope.shutdown does not interrupt newly started threads (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14833

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14833.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 11, 2023

👋 Welcome back alanb! 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 Jul 11, 2023

@AlanBateman The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jul 11, 2023
@AlanBateman AlanBateman marked this pull request as ready for review July 12, 2023 06:54
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 12, 2023
@mlbridge
Copy link

mlbridge bot commented Jul 12, 2023

Webrevs


// fork subtask to shutdown
scope.fork(() -> {
scope.shutdown();
Copy link
Member

Choose a reason for hiding this comment

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

Hello Alan, the proposed source change in ThreadFlock and the reason for that change appear good to me.
However, as far as I understand, it appears to me that this test may not be reproducing the issue where shutdown gets called when there are threads that are about to start. From what I see in the API and implementation of scope.fork(), when the fork() returns, it's guaranteed that a Thread for the subtask has been started (keeping aside the failed to start cases). So in this test here, when we reach this point where we attempt a shutdown() all 15 "beforeShutdown" subtasks would already have threads that are started and alive. i.e. there won't be any "about to be started thread". As for the 15 "afterShutdown" forks() that follow, they would already notice that the scope is shutdown and won't start the new threads.
Did I misunderstand this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for the 15 "afterShutdown" forks() that follow, they would already notice that the scope is shutdown and won't start the new threads.
Did I misunderstand this test?

The test arranges for a subtask to do shutdown, it's not done by the main task. That setups up the conditions for the shutdown to race with the subsequent forking done by the main task.

Copy link
Member

Choose a reason for hiding this comment

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

Ah! Indeed, I missed that crucial detail. So the shutdown() call itself can happen when one of the "afterShutdown" subtask is being forked and a new thread being created for it. Makes sense. Thank you for that explanation.

@openjdk
Copy link

openjdk bot commented Jul 12, 2023

@AlanBateman 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:

8311867: StructuredTaskScope.shutdown does not interrupt newly started threads

Reviewed-by: jpai

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

  • aa7367f: 8311921: Inform about MaxExpectedDataSegmentSize in case of pthread_create failures on AIX
  • 753bd56: 8311870: Split CompressedKlassPointers from compressedOops.hpp
  • 0b0e064: 8311656: Shenandoah: Unused ShenandoahSATBAndRemarkThreadsClosure::_claim_token
  • fd7fddb: 8295894: Remove SECOM certificate that is expiring in September 2023
  • d82ade3: 8310683: Refactor StandardCharset/standard.java to use JUnit
  • aac903d: 8311805: Clean up ScrollPane: drop redundant initialiser, mark scroller final
  • 15195e6: 8310066: Improve test coverage for JVMTI GetThreadState on carrier and mounted vthread
  • 6cb9ec3: 6960866: [Fmt-Ch] ChoiceFormat claims impossible and unimplemented functionality
  • 401c3de: 8311645: Memory leak in jspawnhelper spawnChild after JDK-8307990
  • e154b0d: 8311606: Change read_icc_profile() to static function in java.desktop/share/native/libjavajpeg/imageioJPEG.c
  • ... and 1 more: https://git.openjdk.org/jdk/compare/00c7f914c665a77842d32eb8f760dcbbbda66554...master

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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 12, 2023
@AlanBateman
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 13, 2023

Going to push as commit 92a04e2.
Since your change was applied there have been 27 commits pushed to the master branch:

  • f60c1f9: 8294401: Update jfr man page to include recently added features
  • 1b0dd7c: 8310108: Skip ReplaceCriticalClassesForSubgraphs when EnableJVMCI is specified
  • a38a421: 8311917: MAP_FAILED definition seems to be obsolete in src/java.desktop/unix/native/common/awt/fontpath.c
  • 812dadb: 8311788: ClassLoadUnloadTest fails on AIX after JDK-8193513
  • 11a5115: 8311556: GetThreadLocalStorage not working for vthreads mounted during JVMTI attach
  • a38582e: 8311691: C2: Remove legacy code related to PostLoopMultiversioning
  • 38f7412: 8311609: [windows] Native stack printing lacks source information for dynamically loaded dlls
  • e51472e: 8309566: Migrate away from TagletWriter and TagletWriterImpl
  • fb90af8: 8311380: Prepare java.desktop for C++17
  • 743e8b8: 8306785: fix deficient spliterators for Sequenced Collections
  • ... and 17 more: https://git.openjdk.org/jdk/compare/00c7f914c665a77842d32eb8f760dcbbbda66554...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 13, 2023
@openjdk openjdk bot closed this Jul 13, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 13, 2023
@openjdk
Copy link

openjdk bot commented Jul 13, 2023

@AlanBateman Pushed as commit 92a04e2.

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

@AlanBateman
Copy link
Contributor Author

/backport jdk21

@openjdk
Copy link

openjdk bot commented Jul 13, 2023

@AlanBateman the backport was successfully created on the branch AlanBateman-backport-92a04e20 in my personal fork of openjdk/jdk21. To create a pull request with this backport targeting openjdk/jdk21:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 92a04e20 from the openjdk/jdk repository.

The commit being backported was authored by Alan Bateman on 13 Jul 2023 and was reviewed by Jaikiran Pai.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21:

$ git fetch https://github.com/openjdk-bots/jdk21.git AlanBateman-backport-92a04e20:AlanBateman-backport-92a04e20
$ git checkout AlanBateman-backport-92a04e20
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21.git AlanBateman-backport-92a04e20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
2 participants