Skip to content

[Process][2.2] Fix #8739 #8741

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

Merged
merged 5 commits into from
Aug 13, 2013
Merged

Conversation

romainneutron
Copy link
Contributor

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

This adds a fix to #8739. Whenever a call is done to to any non-blocking methods (Process::isRunning, Process::isStopped, Process::isTerminated, Process::getStatus, Process::getPid...), buffers are read, and callback executed.

Such code will now work :

$process->start(function ($type, $data) {
    echo $data;
});

while ($process->isRunning()) {
    // some stuff
    // callback is executed
}

@romainneutron
Copy link
Contributor Author

some internal calls of Process::updateStatus may need an update after merging this in 2.3 (Process::getPid, probably some other)

@romainneutron
Copy link
Contributor Author

Tests are failing because of another test suite than Process :

Symfony\Component\Config\Tests\Resource\DirectoryResourceTest::testIsFreshDeleteFile
->isFresh() returns false if an existing file is removed
Failed asserting that true is false.

fabpot added a commit that referenced this pull request Aug 13, 2013
This PR was merged into the 2.2 branch.

Discussion
----------

[Process][2.2] Fix #8739

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

This adds a fix to #8739. Whenever a call is done to to any non-blocking methods (`Process::isRunning`, `Process::isStopped`, `Process::isTerminated`, `Process::getStatus`, `Process::getPid`...), buffers are read, and callback executed.

Such code will now work :

```
$process->start(function ($type, $data) {
    echo $data;
});

while ($process->isRunning()) {
    // some stuff
    // callback is executed
}
```

Commits
-------

fa769a2 [Process] Add more precision to Process::stop timeout
57d4159 [Process] Avoid zombie process in case of unit tests failure
3ef517b [Process] Fix #8739
7716fb2 [Process] Add failing test for #8739
bff6f3c [Process] Fix CS
@fabpot fabpot merged commit fa769a2 into symfony:2.2 Aug 13, 2013
@fabpot
Copy link
Member

fabpot commented Aug 13, 2013

Merged now. Can you check the additional changes needed in 2.3 and send a PR? Thanks.

hmm, on my computer, this PR slows down the Process unit tests a lot and produces some output:

PHPUnit 3.7.21 by Sebastian Bergmann.

Configuration read from /Users/fabien/Code/github/symfony/symfony/phpunit.xml.dist

SS...................................SS........................  63 / 173 ( 36%)
....S...............S........................sh: line 0: echo: write error: Broken pipe
.........S........ 126 / 173 ( 72%)
............................................S..

Time: 01:41, Memory: 105.75Mb

OK, but incomplete or skipped tests!
Tests: 173, Assertions: 379, Skipped: 8.

@romainneutron
Copy link
Contributor Author

Thanks for the feedback, going to propose a PR for 2.3 right now. Unfortunately, I can not dig later tonight for the slowness / output, will check it tomorrow morning. thanks for the feedback

@romainneutron
Copy link
Contributor Author

2.3 seems ok for me, no need for aditional changes.
I reproduced the error message and slowness on some tests

@@ -343,7 +360,7 @@ public function testPhpDeadlock()

// Sleep doesn't work as it will allow the process to handle signals and close
// file handles from the other end.
$process = $this->getProcess('php -r "while (true) {}"');
$process = $this->getProcess('php -r "sleep 4"');
Copy link
Contributor

Choose a reason for hiding this comment

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

@romainneutron Are you sure about this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I explained in #8740 :

On my computer, zombie processes might have remain in case of unit test failure.
It happend that some infinite loops were running and slowing down my system. A ps call alerted me that many (~100) php -r "while (true) {}" were running after half an hour debugging things.

In this case, we trigger the Process::stop call in the __destruct method. I don't see any problem here, do you ?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Notice the comment above the code (it says sleep wouldn't work)
  2. shouldn't it be sleep(4); rathern than sleep 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are indeed right, I'll make some more tests tomorrow

romainneutron added a commit to romainneutron/symfony that referenced this pull request Aug 14, 2013
fabpot added a commit that referenced this pull request Aug 14, 2013
This PR was merged into the 2.2 branch.

Discussion
----------

[Process] Fix #8746 : slowness added in unit tests since #8741

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

Commits
-------

8c4bae3 [Process] Revert change
8d9c7c6 [Process] Fix #8746 : slowness added in unit tests since #8741
fabpot added a commit that referenced this pull request Aug 14, 2013
* 2.2:
  [Process] Revert change
  [Process] Fix #8746 : slowness added in unit tests since #8741
fabpot added a commit that referenced this pull request Aug 14, 2013
This PR was merged into the 2.3 branch.

Discussion
----------

[Process] Fix #8742 : Signal-terminated processes are not successful

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | require #8741 to be merged to pass tests
| Fixed tickets | #8742
| License       | MIT

Commits
-------

909fab6 [Process] Fix #8742 : Signal-terminated processes are not successful
fabpot added a commit that referenced this pull request Aug 14, 2013
* 2.3:
  [Process] Revert change
  [Process] Fix #8746 : slowness added in unit tests since #8741
  [Process] Fix #8742 : Signal-terminated processes are not successful
  corrected English grammar (s/does not exists/does not exist)
  [Process] Add more precision to Process::stop timeout
  [Process] Avoid zombie process in case of unit tests failure
  [Process] Fix #8739
  [Process] Add failing test for #8739
  [Process] Fix CS
  [TwigBridge] removed superflous ; when rendering form_enctype() (closes #8660)
  Fixed documentation grammar for AuthenticationManagerInterface::authenticate()
  [Validator] fixed the wrong isAbstract() check against the class (fixed #8589)
  [TwigBridge] Prevent code extension to display warning
  Fix internal sub-request creation
  [FrameworkBundle] made code more generic
  [Form] Moved auto_initialize option to the BaseType
  Use strstr instead of strpos
  Make sure ContextErrorException is loaded during compile time errors
  Fix empty process argument escaping on Windows
  Ignore null value in comparison validators

Conflicts:
	src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
	src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php
	src/Symfony/Component/Process/Process.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants