Skip to content
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

Symfony 4.4.0-BETA2: Segmentation fault with PHPUnit 6.5.14 #34368

Closed
COil opened this issue Nov 13, 2019 · 29 comments · Fixed by symfony/recipes#677
Closed

Symfony 4.4.0-BETA2: Segmentation fault with PHPUnit 6.5.14 #34368

COil opened this issue Nov 13, 2019 · 29 comments · Fixed by symfony/recipes#677

Comments

@COil
Copy link
Contributor

@COil COil commented Nov 13, 2019

Symfony version(s) affected: 4.4.0-BETA2

PHP Version: 7.2.17

Description
PHPunit crashed with a segmentation fault.

[21:50:49] coil@Mac-mini-de-COil.local:/Users/coil/Sites/strangebuzz.com$ bin/phpunit --stop-on-failure
#!/usr/bin/env php
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
Testing Project Test Suite
..fish: 'bin/phpunit --stop-on-failure' terminated by signal SIGSEGV (Address boundary error)

Or when launching with my MakeFile:

[22:02:18] coil@Mac-mini-de-COil.local:/Users/coil/Sites/strangebuzz.com$ make test
bin/phpunit --stop-on-failure
#!/usr/bin/env php
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Testing Project Test Suite
..make: *** [test] Segmentation fault: 11

Additional context
The site looks to work without problem, but as I can't run all the tests I can't be sure.
It's seems that failing test-suites contains loops. No error when accessing the URLs with the browser.

May be related :
phpunit-segmentation-fault-11

If you need more information, tell me. COil 🙂

@derrabus

This comment has been minimized.

Copy link
Contributor

@derrabus derrabus commented Nov 13, 2019

A segfault is first of all an issue of the php runtime, so the php version would be interesting to know. You could also try to update your php installation if you haven't done so already.

@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 13, 2019

PHP version added. Symfony 4.4 is supposed to work with 7.2.

@derrabus

This comment has been minimized.

Copy link
Contributor

@derrabus derrabus commented Nov 13, 2019

Symfony 4.4 is supposed to work with 7.2.

True, but no php application should ever be able to trigger a segfault. So this is primarily a php bug that you're hitting. Would upgrading to the latest php 7.2 release be a big problem for you?

@nicolas-grekas

This comment has been minimized.

Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 13, 2019

There is one case when php segfaults and it's userland's fault: infinite recursion.
Xdebug is able to report them, can you please try running this crash with xdebug enabled and report back what you get?

@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 14, 2019

I have enabled Xdebug:

[08:01:09] coil@Mac-mini-de-COil.local:/Users/coil/Sites/strangebuzz.com$ php -i | grep xdebug.max_nesting_level
xdebug.max_nesting_level => 256 => 256

But the recursion is not caught. Do I have something more to set-up?

@derrabus

This comment has been minimized.

Copy link
Contributor

@derrabus derrabus commented Nov 14, 2019

No, that should do the trick. So if there‘s no recursion, next things you can try:

  • Upgrade to the latest patch release of the php branch you‘re using (7.2.24 or 7.2.25RC1 in your case)
  • If you use any exotic php extensions, disable them and check if the error still occurs.
@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 14, 2019

PHP upgraded , same result.

[20:16:41] coil@Mac-mini-de-COil.local:/Users/coil/Sites/strangebuzz.com$ php -v
PHP 7.2.24 (cli) (built: Oct 25 2019 11:14:44) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.8.0, Copyright (c) 2002-2019, by Derick Rethans
    with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
[20:16:49] coil@Mac-mini-de-COil.local:/Users/coil/Sites/strangebuzz.com$ make test
bin/phpunit --stop-on-failure
#!/usr/bin/env php
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Testing Project Test Suite
...make: *** [test] Segmentation fault: 11
[20:16:51] coil@Mac-mini-de-COil.local:/Users/coil/Sites/strangebuzz.com$
@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 14, 2019

The bug come from loops like this:

    /**
     * @covers BlogController::show()
     */
    public function testShow(): void
    {
        $kernelBrowser = static::createClient();
        foreach (self::ARTICLES as $lang => $articles) {
            foreach ($articles as $slug) {
                $this->assertResponseIsOk($kernelBrowser, '/'.$lang.'/blog/'.$slug);
            }
        }

        $kernelBrowser->request('GET', '/en/blog/'.self::INACTIVE);
        $this->assertTrue($kernelBrowser->getResponse()->isNotFound());
    }

If I replace the loop by using a PHPUnit dataprovider, it works.

The question is: why does it work with Symfony 4.3?

@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 14, 2019

Really weird, I am playing with the tests and it's related with the number of times: $kernelBrowser->request('GET', $url); is called.

Using dataProviders only make the segfault happen later.

@nicolas-grekas

This comment has been minimized.

Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 14, 2019

Can you maybe profile with Blackfire to see how memory is used with a number of iterations that doesn't make the script crash?

@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 15, 2019

I have tested on my Ubuntu Workstation with the same PHP version:

[13:14:47] lvernet@lvernetZ240:~/workspace/strangebuzz.com$ php -v
PHP 7.2.24-0ubuntu0.18.04.1 (cli) (built: Oct 28 2019 12:07:07) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

And this time, everything works correctly. So It may be a PHP parameter of Brew or something like this. Still annoying.

@nicolas-grekas

This comment has been minimized.

Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 15, 2019

Can you please try with this change?

--- a/src/Kernel.php
+++ b/src/Kernel.php
@@ -34,6 +34,7 @@ class Kernel extends BaseKernel
     {
         $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
         $container->setParameter('container.dumper.inline_class_loader', true);
+        $container->setParameter('container.dumper.inline_factories', true);
         $confDir = $this->getProjectDir().'/config';
 
         $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 15, 2019

When calling $client->insulate(true); before the request, it works. But the tests are very slow. (30 seconds instead of 6)

@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 15, 2019

I don't understand, now it works, even without the insulate calls:

[22:16:50] coil@Mac-mini-de-COil.local:/Users/coil/Sites/strangebuzz.com$ php -v
PHP 7.2.24 (cli) (built: Oct 25 2019 11:14:44) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
[22:22:30] coil@Mac-mini-de-COil.local:/Users/coil/Sites/strangebuzz.com$ make test
bin/phpunit --stop-on-failure
#!/usr/bin/env php
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Testing Project Test Suite
..................                                                18 / 18 (100%)

Time: 6.8 seconds, Memory: 70.25MB

OK (18 tests, 163 assertions)

The memory consumption doesn't look high. Well, I guess we can close this issue. I'll check on the next betas. Thanks for you help.

@nicolas-grekas

This comment has been minimized.

Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 15, 2019

Did you apply my patch or not?

@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 15, 2019

No, I can't reproduce now. But I noticed that tests are faster with this line.

$container->setParameter('container.dumper.inline_factories', true);

3,8 seconds vs 4.8 seconds. 🙂

@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 17, 2019

I am closing this if it's OK for you.

@COil COil closed this Nov 17, 2019
@jul6art

This comment has been minimized.

Copy link

@jul6art jul6art commented Nov 22, 2019

Can you please try with this change?

--- a/src/Kernel.php
+++ b/src/Kernel.php
@@ -34,6 +34,7 @@ class Kernel extends BaseKernel
     {
         $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
         $container->setParameter('container.dumper.inline_class_loader', true);
+        $container->setParameter('container.dumper.inline_factories', true);
         $confDir = $this->getProjectDir().'/config';
 
         $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');

That solved the problem for me, in PHP7.3 with brew

@YetiCGN

This comment has been minimized.

Copy link

@YetiCGN YetiCGN commented Nov 26, 2019

There is one case when php segfaults and it's userland's fault: infinite recursion.

Thanks! That was a good pointer to prohibit the possibilty of any recursion in our current REST API project.

Xdebug is able to report them, can you please try running this crash with xdebug enabled and report back what you get?

I have some weird behavior with Symfony 4.4.0 and PHPUnit as well. Tried in combination with PHPUnit 8.3, 7.5 and 6.5. With xdebug enabled the tests just run very very slow but never crash or catch an infinite recursion.

I will try the change to Kernel.php above and maybe get some more info.

@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 26, 2019

I also have this "slowness" problem. But only when the container need to be recompiled (after a change in services.yml for example). At the second run, the tests are fast as they used to.

@YetiCGN

This comment has been minimized.

Copy link

@YetiCGN YetiCGN commented Nov 27, 2019

I have now thrown out xdebug and exchanged it for pcov, no more slowness at all!

The segfaults are still there with Symfony 4.4.0 on PHP 7.4.0rc6, though. Had to revert to Symfony 4.3.8.

@Devristo

This comment has been minimized.

Copy link
Contributor

@Devristo Devristo commented Nov 27, 2019

I'm watching this thread as I am still experiencing occassional segfaults when running tests using the kernel with PHP 7.4.0 RC6 as well.

Trimming the container as much as possible (excluding classes for value objects etc) seem to have lower the chance of errors but they still occasionally happen to me after a code change.

Unfortunately I could not create a reproducing example yet. Will give it another go later today.

Remember: could very well be a bug in PHP instead of symfony.

@nicolas-grekas

This comment has been minimized.

Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 27, 2019

Does #34580 fix the issue? Could anyone give it a try?

@Devristo

This comment has been minimized.

Copy link
Contributor

@Devristo Devristo commented Nov 27, 2019

Sorry I forgot to mention I did try that patch. It seems to lower the chances for me, but it is still happening occassionally. However it definitely helps. Will try to debug my issue later today :)

@YetiCGN

This comment has been minimized.

Copy link

@YetiCGN YetiCGN commented Nov 28, 2019

Does #34580 fix the issue? Could anyone give it a try?

I can confirm that it mitigates the problem. I have added "symfony/http-kernel": "4.4.x-dev@dev", to my composer.json. I have only checked one Symfony 4.4 project, will validate with the other one shortly.

@Devristo

This comment has been minimized.

Copy link
Contributor

@Devristo Devristo commented Nov 28, 2019

It took me a while to create a core dump, it suggests pcov (krakjoe/pcov#40) is the culprit. Will investigate more, but for now it seems unrelated to this issue.

@YetiCGN

This comment has been minimized.

Copy link

@YetiCGN YetiCGN commented Nov 28, 2019

I agree, I have segfaults without either pcov or xdebug as well:

PHPUnit 8.3.5 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.0RC6
Configuration: /mnt/[...]/phpunit.xml.dist

Testing Explicatis Website Tests
...............................................................  63 / 191 ( 32%)
............................................................... 126 / 191 ( 65%)
.............Segmentation fault (core dumped)
@COil

This comment has been minimized.

Copy link
Contributor Author

@COil COil commented Nov 28, 2019

Hi @nicolas-grekas , I can confirm #34580 fixed the slowness issue for me.

@YetiCGN

This comment has been minimized.

Copy link

@YetiCGN YetiCGN commented Nov 28, 2019

Dramatically! Our test suite here dropped from 26 minutes runtime and 1,000 MB of memory to a mere 2 minutes and 176.5 MB! Even with PCOV activated for code coverage, it takes only 2.3 minutes for 191 tests and 1,169 assertions now.

Edit: I should point out that it was only slow immediately after the upgrade to Symfony 4.4.0. So it's back to normal speed. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.