On Thu, 7 Jul 2022 19:08:35 GMT, Roger Riggs <rri...@openjdk.org> wrote:
> 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. This pull request has now been integrated. Changeset: 620c8a04 Author: Roger Riggs <rri...@openjdk.org> URL: https://git.openjdk.org/jdk/commit/620c8a045f92126c2552347b9f369405ab2d6d36 Stats: 144 lines in 2 files changed: 143 ins; 0 del; 1 mod 8289643: File descriptor leak with ProcessBuilder.startPipeline Reviewed-by: alanb, jpai, lancea ------------- PR: https://git.openjdk.org/jdk/pull/9414