-
Notifications
You must be signed in to change notification settings - Fork 5.9k
8210549: Runtime.exec: in closeDescriptors(), use FD_CLOEXEC instead of close() #25301
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
4eef7ba
to
cc80bb3
Compare
@tstuefe 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 no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
3e17175
to
cd9c002
Compare
cd9c002
to
c5dc302
Compare
Webrevs
|
Ping @RogerRiggs ? And @simonis, perhaps? |
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.
Looks good
@RogerRiggs Thank you. I hold this up a few days until JDK26 since its not super critical. Would one review be sufficient or do I need more? |
Leaving it to 26 is good. One review is ok. |
…escriptors-use-FD_CLOEXEC-instead-of-close-
…escriptors-use-FD_CLOEXEC-instead-of-close-
Hi, please consider the following patch.
This patch replaces the existing close-file-descriptors-logic we follow before exec'ing a target binary: instead of explicitly closing the file descriptors, we mark them as CLOEXEC. That simplifies the logic: it gets rid of the awkward tiptoeing around the fact that we need to keep alive a few file descriptors: the fail pipe fd needs to be kept open right up to the exec(), and we cause opening internal file descriptors during our iteration of open file handles from /proc.
This patch also makes future developments easier: I am working on improving logging during child process spawning (https://bugs.openjdk.org/browse/JDK-8357100), and there we have a similar problem where we need to keep a logfile fd open right up to the point exec() happens).
Note: Using fcntl() with FD_CLOEXEC should work on all our POSIX platforms, since we rely on it already, see unconditional use of that flag here:
jdk/src/java.base/unix/native/libjava/childproc.c
Lines 408 to 409 in 3acfa9e
This patch also fixes two subtle bugs:
Testing:
We already have the PipelineLeak test, but I also added a new test that checks that we don't accidentally leak file descriptors even if those had been opened outside the JVM and without FD_CLOEXEC.
I verified that the test correctly detects a broken implementation that leaks file descriptors.
I verified that with this patch, we close all file descriptors. I also verified the fallback path (where we brute-force-iterate all descriptors up to _SC_OPEN_MAX).
I ran manually all tests from test/jdk/java/base/Process*, and verified that these tests run as part of the GHAs, which are green.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25301/head:pull/25301
$ git checkout pull/25301
Update a local copy of the PR:
$ git checkout pull/25301
$ git pull https://git.openjdk.org/jdk.git pull/25301/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25301
View PR using the GUI difftool:
$ git pr show -t 25301
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25301.diff
Using Webrev
Link to Webrev Comment