Subprocesses do not close open FDs
|Reported by:||Baughn||Owned by:|
|Type of failure:||Test Case:|
|Related Tickets:||Differential Rev(s):|
When creating a subprocess, for example with runInteractiveProcess, only pipes that are created in the process of creating the process are closed appropriately; any FDs created elsewhere in the program are ignored. As unix pipes are only considered closed once every process that could conceivably write to one has closed it, one consequence of this is that programs that rely on detecting EOF will be unable to do so. Another is that the system may leak FDs over the runtime of the program, conceivably running out.
As an example, this makes it impossible to write a fully functional shell with pipes in GHC; in a shell command like "<main program> | cat | cat", the second cat may acquire a reference to the pipe used for writing to the first one, which will prevent that pipe from ever being considered closed.
A brute-force solution would be to attempt to close every possible FD when creating subprocesses. This is undesirable for several reasons - most obviously performance, but also because there are legitimate reasons to pass FDs other than stdin/out/err to a subprocess. A more elegant one would be for all FDs opened by any means to be marked as close-on-exec on creation, and provide a call to clear this bit if transferring it to a specific subprocess is desired.
Change History (8)
Changed 9 years ago by Paczesiowa
comment:3 Changed 9 years ago by simonmar
- difficulty set to Unknown
- Resolution set to duplicate
- Status changed from new to closed
comment:4 Changed 9 years ago by simonmar
- Component changed from Runtime System to libraries/process