8377935: (process) jspawnhelper race can cause hangs in ProcessBuilder - fix for FORK mode#29725
Draft
tstuefe wants to merge 2 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
|
I think there is a hack to unset // process that calls posix_spawn():
int fd = /* from pipe2() */;
int fd2 = fcntl(fd, F_DUPFD_CLOEXEC, 0);
// both fd and fd2 now have FD_CLOEXEC set
posix_spawn_file_actions_t actions;
posix_spawn_file_actions_init(&actions);
posix_spawn_file_actions_adddup2(&actions, fd, fd2);
posix_spawn(/*...*/, &actions, /*...*/);
// process created by posix_spawn() can now use fd2 as FD_CLOEXEC was unset by the dup2 action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A customer reported a process-hanging issue (intermittent hangs in ProcessBuilder.start).
*Note: Fixing it for FORK mode is trivial; fixing it for POSIX_SPAWN is very difficult. Therefore, I decided to patch the FORK mode immediately to get backports underway. This issue is a sub-issue of the real problem and addresses only the FORK mode fix. Fixing POSIX_SPAWN will happen in a separate RFE. *
Process A (a JVM) spawns, via ProcessBuilder.start, child process B. To do that, it will create a fail pipe to listen for error messages from the child. Child B:
Parent A:
If child execve succeeds, it will automatically close the write end of the pipe in child B. The parent gets an EOF and knows the child succeeded in doing execve.
If child B execve fails, it sends an error message to the parent via the still-open write end of the pipe.
However, if between the parent creating a pipe and the parent closing the write end of the pipe, some native thread in the parent forks off via a native - not controlled by us - fork() call, that new child process C now also carries a copy of the write end of the pipe. The fail pipe will stay open as long as the second child process C did not end. That, in turn, causes the parent process to hang in forkAndExec() waiting for the fail pipe to go away.
For
-Djdk.lang.Process.launchMechanism=FORK, we can provide a complete fix for Linux and xxxBSD (using pipe2), and at least make the error significantly less likely on MacOS and AIX (by using pipe() and setting their file descriptors to CLOEXEC right away).Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/29725/head:pull/29725$ git checkout pull/29725Update a local copy of the PR:
$ git checkout pull/29725$ git pull https://git.openjdk.org/jdk.git pull/29725/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 29725View PR using the GUI difftool:
$ git pr show -t 29725Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/29725.diff