[Process] Do not reset stdout/stderr pipes on Interrupted system call

When `stream_select` is called and return false because of an `Interrupted
system call`, pipes are currently reset to an empty array.
As a result, both error-output and output are empty whereas the
exitcode is 0 (successful process).
merged branch romainneutron/StreamSelect (PR #6540)

This PR was merged into the 2.1 branch.

Commits
-------

fa6fb6f [Process] Do not reset stdout/stderr pipes on Interrupted system call

Discussion
----------

[Process][2.1] Do not reset stdout/stderr pipes on stream_select failure

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT

When `stream_select` is called and failed, pipes are currently reset to an empty array. As a result, both error-output and output are empty whereas the exitcode is 0 (successful process).

There is no reason (at least I don't see it) to reset pipes when an error occurs.

---------------------------------------------------------------------------

by fabpot at 2013-01-04T08:18:03Z

This behavior was introduced by @Seldaek in bcf8cf91. Any reason?

---------------------------------------------------------------------------

by Seldaek at 2013-01-04T17:22:33Z

The rationale was that if stream_select failed, it will fail every time (maybe this is an incorrect assumption and I introduced a bug there). Since the while loop checks for $this->pipes being not empty, if the process dies off and stream_select() starts failing, it will be stuck in the while loop forever. That's what I was fixing there. As far as I can tell, your fix reintroduces that problem. Can you explain a bit more what you mean by "error-output and output are empty"? Maybe adding a test for the case you are seeing would help too?

---------------------------------------------------------------------------

by romainneutron at 2013-01-04T17:47:00Z

Hi !

I'm actually using `Process` in a amqp client using PhpAmqpLib. Sometimes both output and error-output of a process are empty whereas the process returned with an exitcode equal to 0.

By *empty*, I mean that the output of both `$process->getOuptut()` and `$process->getErrorOuptut()` are equal to `''`.

I removed the `@` before the `stream_select` and realized that some calls where failing :

```
stream_select(): unable to select [4]: Interrupted system call (max_fd=13) in .../vendor/symfony/process/Symfony/Component/Process/Process.php on line 341
```

With my patch, it appears that if a `stream_select` call fails one time, it can be called with success a second time.

Adding a test case that triggers this error does not seem easy as it seems system related.

What do you think about it ?

---------------------------------------------------------------------------

by Seldaek at 2013-01-04T17:52:04Z

Ok I see. So I guess your fix makes sense since stream_select can fail legitimately, but it's not the whole story. If it fails because the process died off (or whatever the cause was on windows) we shouldn't keep trying forever. Maybe just adding a limit of N retries that is reset whenever a call succeeds would be enough to go over the odd system call being interrupted without allowing infinite loops. Not sure what N makes sense.

---------------------------------------------------------------------------

by igorw at 2013-01-04T17:53:45Z

As per the `stream_select` manpage it can return false when interrupted by a system call. That does not indicate that something is broken. However, I'm not sure if it is possible to distinguish between actual errors and interrupts without capturing and parsing the error message.

---------------------------------------------------------------------------

by romainneutron at 2013-01-04T18:50:56Z

I've updated the PR to consider the error message as it's currently the only solution to find out why `stream_select` failed

---------------------------------------------------------------------------

by romainneutron at 2013-01-04T18:59:15Z

Merged fixes suggested by @stloyd  and @Seldaek