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] Check if the pipe array is empty before calling stream_select() #9367

Closed
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
6 participants
@jfposton
Contributor

jfposton commented Oct 24, 2013

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #9280
License MIT
Doc PR

ProcessPipes 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

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
class ProcessDoesNotThrowWarningTest extends \PHPUnit_Framework_TestCase
{
public function testThatProcessDoesNotThrowWarningDuringRun(){

This comment has been minimized.

@stof

stof Oct 24, 2013

Member

This tests should be in the ProcessTest class

@@ -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))) {

This comment has been minimized.

@romainneutron

romainneutron Oct 24, 2013

Member

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();
    }
    // ...
}
$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())

This comment has been minimized.

@cordoval

cordoval Oct 24, 2013

Contributor

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

@romainneutron

This comment has been minimized.

Member

romainneutron commented Oct 24, 2013

As ProcessPipes have been introduced in 2.2, this PR should be done against branch 2.2

@@ -251,6 +251,10 @@ private function readFileHandles($close = false)
*/
private function readStreams($blocking, $close = false)
{
if(empty($this->pipes)){
return [];

This comment has been minimized.

@romainneutron

romainneutron Oct 29, 2013

Member

You should use PHP 5.3 compatible notation as Symfony is compatible from 5.3.3.

@@ -20,6 +20,16 @@
*/
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
{
public function testThatProcessDoesNotThrowWarningDuringRun()
{
@trigger_error('Test Error', E_USER_NOTICE);

This comment has been minimized.

@romainneutron

romainneutron Oct 29, 2013

Member

AFAIK, Symfony PHPUnit confguration converts errors to exception. No need for such test as the error would result in a test failure

This comment has been minimized.

@stof

stof Oct 29, 2013

Member

it will not be converted to an exception because of @

This comment has been minimized.

@romainneutron

romainneutron Oct 29, 2013

Member

I was writing about the test purpose. The test is catching errors.

Romain

On 29 oct. 2013, at 21:15, Christophe Coevoet notifications@github.com
wrote:

In src/Symfony/Component/Process/Tests/AbstractProcessTest.php:

@@ -20,6 +20,16 @@
*/
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
{

  • public function testThatProcessDoesNotThrowWarningDuringRun()
  • {
  •    @trigger_error('Test Error', E_USER_NOTICE);
    

it will not be converted to an exception because of @


Reply to this email directly or view it on
GitHubhttps://github.com//pull/9367/files#r7292973
.

This comment has been minimized.

@jfposton

jfposton Oct 30, 2013

Contributor

@romainneutron I'm not sure what you are trying to say. The point of the test is too see if a suppressed error is generated by ProcessPipes::readStreams() when Process::run() is called. Since it is suppressed I do not believe PHPUnit converts it. The suppressed error causes problems for custom shutdown functions since the error is still hanging around at the end of execution.

@ahilles107

This comment has been minimized.

ahilles107 commented Nov 15, 2013

how about that issue? When it can be merged to 2.3 and released?

@fabpot

This comment has been minimized.

Member

fabpot commented Nov 15, 2013

As mentioned by @romainneutron, this PR must be done on 2.2.

fabpot added a commit that referenced this pull request Nov 15, 2013

bug #9367 [Process] Check if the pipe array is empty before calling s…
…tream_select() (jfposton)

This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #9367).

Discussion
----------

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

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9280
| License       | MIT
| Doc PR        |

ProcessPipes 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

Commits
-------

12f95e2 [Process] Check if the pipe array is empty before calling stream_select()

@fabpot fabpot closed this Nov 15, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment