8000 [Process] Check if the pipe array is empty before calling stream_select() by jfposton · Pull Request #9367 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Process] Check if the pipe array is empty before calling stream_select() #9367

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Check if the pipe array is empty before calling stream_select()
The pipe array is either set to null or is empty occasionally when readStreams() is called. This generates a warning frequently which can cause issues for custom shutdown functions. Adding a check to see if the pipe array is empty should be functionally equivalent without having to generate the error.

Fixes: #9280
  • Loading branch information
jfposton committed Oct 24, 2013
commit e636a40024ef6a7edb867b136d84b280b1b34c6b
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/ProcessPipes.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private function readStreams($blocking, $close = false)
$e = null;

// let's have a look if something changed in streams
if (false === $n = @stream_select($r, $w, $e, 0, $blocking ? ceil(Process::TIMEOUT_PRECISION * 1E6) : 0)) {
if (empty($r) || (false === $n = @stream_select($r, $w, $e, 0, $blocking ? ceil(Process::TIMEOUT_PRECISION * 1E6) : 0))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the check on empty pipes should be done at the beginning of the method. No need to declare variables or check for an interrupted system call when pipes are empty.

public function readStreams($blocking, $close = false) 
{
    if (empty($this->pipes)) {
        return array();
    }
    // ...
}

// if a system call has been interrupted, forget about it, let's try again
// otherwise, an error occured, let's reset pipes
if (!$this->hasSystemCallBeenInterrupted()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Process\Tests;

use Symfony\Component\Process\Process;

class ProcessDoesNotThrowWarningTest extends \PHPUnit_Framework_TestCase
{
public function testThatProcessDoesNotThrowWarningDuringRun(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests should be in the ProcessTest class

@trigger_error('Test Error', E_USER_NOTICE);
$process = $this->getProcess("php -r 'sleep(3)'");
$process->run();
$actualError = error_get_last();
$this->assertEquals('Test Error', $actualError['message']);
$this->assertEquals(E_USER_NOTICE, $actualError['type']);
}
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run a php-cs-fixer to fix the spacings

{
return new Process($commandline, $cwd, $env, $stdin, $timeout, $options);
}

}

0