-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Process] Use a pipe for stderr in pty mode to avoid mixed output between stdout and stderr #59949
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
[Process] Use a pipe for stderr in pty mode to avoid mixed output between stdout and stderr #59949
Conversation
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.
Can you please add a test case or is it hard to achieve?
Was written in den PR header
Like i said, test is hard to achieve it happens randomly our reproducer for this is the current script : <?php
require 'vendor/autoload.php';
use Symfony\Component\Process\Process;
$reference = run_process();
echo "Output Reference:\n";
echo $reference;
echo "\n";
for ($i=0; $i < 100_000; $i++) {
if ($i > 0 && $i % 80 === 0) {
echo "\n";
}
echo '.';
$output = run_process();
if ($output !== $reference) {
echo "\n!!Output changed!!\n";
echo "New output:\n";
echo "$output\n";
exit(1);
}
}
function run_process(){
$process = new Process(['cat', __FILE__]);
// If you comment the following line, the test become stable
$process->setPty(true);
$process->mustRun();
return $process->getOutput();
} |
f6b1b56
to
001b418
Compare
I spoke to soon, i added a test, before this change everything was in the |
… between stdout and stderr
001b418
to
ba755a8
Compare
Failed test seems to not be related, so ready for review i guess |
Good catch, thanks @joelwurtz. |
This PR split the stderr in a pipe to correctly split stdout / stderr when using
->setPty
When using
pty
for pipes, PHP will only open only one pty and share the "same" fd for all pipes (it use dup but the original fd is the same)Which means there is a possibility than stdout goes to stderr (or vice versa) when using
pty
for both stdout and stderr.I did not make a test as this behavior is erratic and happens under other conditions that are hard to find (see related issue to see reproducer, we have to do some iterations before it happens)