RFR: 8289643: File descriptor leak with ProcessBuilder.startPipeline [v7]

Roger Riggs rriggs at openjdk.org
Mon Jul 18 17:53:16 UTC 2022


> The `ProcessBuilder.pipelineStart()` implementation does not close all of the file descriptors it uses to create the pipeline of processes.
> 
> The process calling `pipelineStart()` is creating the pipes between the stages.
> As each process is launched, the file descriptor is inherited by the child process and
> the child process `dup`s them to the respective stdin/stdout/stderr fd.  
> These copies of inherited file descriptors are handled correctly.
> 
> Between the launching of each Process, the file descriptor for the read-side of the pipe for the output of the previous process is kept open (in the parent process invoking `pipelineStart`).  The file descriptor is correctly passed to the child and is dup'd to the stdin of the next process.
> 
> However, the open file descriptor in the parent is not closed after it has been used as the input for the next Process. 
> The fix is to close the fd after it has been used as the input of the next process.
> 
> A new test verifies that after `pipelineStart` is complete, the same file descriptors are open for Unix Pipes as before the test.
> The test only runs on Linux using the /proc/<pid>/fd filesystem to identify open file descriptors.
> 
> The bug fix is in `ProcessBuilder.pipelineStart` and is applicable to all platforms.

Roger Riggs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 10 additional commits since the last revision:

 - Remove diagnostics output from ProcessBuilder
 - Merge branch '8289643-pipeline-start-leak' of https://github.com/RogerRiggs/jdk into 8289643-pipeline-start-leak
 - Add DEBUG diagnostics to determine cause of GitHub Action test failures due to unexpected pipes
 - Merge branch 'master' into 8289643-pipeline-start-leak
 - Add DEBUG diagnostics to determine cause of GitHub Action test failures due to unexpected pipes
 - Use DirectoryStream and handle IOExceptions
 - remove debug output
 - Add TWR for Files.walk of /proc
 - Cleanup of PipelineLeaksFD test improving error messages and source cleanup.
 - 8289643: File descriptor leak with ProcessBuilder.startPipeline

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/9414/files
  - new: https://git.openjdk.org/jdk/pull/9414/files/ffddeed9..095e76b2

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=9414&range=06
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=9414&range=05-06

  Stats: 81632 lines in 1825 files changed: 42313 ins; 25394 del; 13925 mod
  Patch: https://git.openjdk.org/jdk/pull/9414.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/9414/head:pull/9414

PR: https://git.openjdk.org/jdk/pull/9414


More information about the core-libs-dev mailing list