Repository navigation
Conversation
The destination kept the source's STDOUT pipe as its own input pipe after proc_open(), so the parent still held a read end of the pipe until the destination was closed. When the destination exited early, the source did not get a broken pipe, and waiting for the source blocked until its timeout. The parent's copy is now closed once the destination has inherited the pipe.
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.
Problem
When a
Processis passed asstdinof another one and the destination exits early (it needs only the first part ofthe input), the source does not get a broken pipe. Waiting for the source then blocks until its timeout, unless the
caller happens to wait for the destination first.
Reproduction
Linux, PHP 8.2 and 8.5:
ProcessTimeoutExceptionafter 10.0 s; with the fix the source exits in 0.01 s.Root cause
The source's STDOUT pipe is passed to
proc_open()of the destination. PHP duplicates it for the child and leaves theoriginal open.
Processkept that original as the destination's$inputPipe($pipes + $descriptors, there is no$pipes[0]for a resource descriptor), so the parent held a read end of the pipe until the destination was closed(when a wait for it saw it finish, or when the object was destroyed).
Solution
The parent's copy is closed right after
proc_open(), the child has its own.writeStdInput()on such a destinationthrows
InvalidStateExceptionas for a closed input (before, it wrote into a read end);closeStdInput()does nothing.Tests
Process.piping.ownership.phpt: an early exit of the destination (the source exits on its write error within seconds;before:
ProcessTimeoutExceptionafter 10 s); a three-stage pipeline whose last stage exits early; STDIN of thedestination; the source no longer captures its STDOUT; a destination that fails to start leaves the source's output
intact. Skipped on Windows, where piping throws
NotSupportedException.Verified
ProcessTimeoutExceptionafter 10 s); it is skippedon Windows.
Process.*tests pass on every environment below; no process is left behind.tester tests -swith the Tester fromcomposer install, as in CI) on the same environments: no failurethat does not occur on master as well (here:
intlnot loaded, file permissions of a WSL-mounted drive, the PHPStanversion printing a type differently, an intermittent
FileSystem.copy).--strict-types) and PHPStan: no errors.php:*-cli); Windows 11 PHP 8.2, 8.3, 8.4, 8.5, 8.6 (official NTSbuilds), 8.5 ZTS and a PHP 8.5 development build.
as well:
types/TypesTest.phpton every job (a newer PHPStan prints(float|int); it passed on master's last CI runon 2026-11-06 and fails on master locally now) and
Process.environment.phpton Windows PHP 8.5 and 8.6 (fails inmaster's last CI run).
Known limitations
kept blocked by the parent.