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

Segmentation fault - was: Seeking help with endless loop #606

Open
kevinpapst opened this issue Aug 29, 2024 · 5 comments
Open

Segmentation fault - was: Seeking help with endless loop #606

kevinpapst opened this issue Aug 29, 2024 · 5 comments

Comments

@kevinpapst
Copy link
Contributor

kevinpapst commented Aug 29, 2024

I have a strange issue that I cannot reproduce in CI: PHPStan execution does not end locally, it gets stuck at a certain code point (see example below) and runs until PHP timeout occurs after 300 seconds.

Usually my Symfony 6.4 app is analyzed in ~ 15 seconds, but with a recent code change on my end (a Doctrine subselect was added) it doesn't end, CPU is at 100% and RAM usage increases constantly (after 20 seconds its at 6GB+).

I use a Macbook M3 and tried PHP 8.1 and 8.3 with same results.
This code runs without issue in a GitHub action (Ubuntu latest with PHP 8.1 / 8.2 / 8.3).
PHPStan is installed in the project.
Composer packages are the same, all PHPstan configs are fetched from phpstan.neon.
The code is the same locally and in CI, besides the minor version of PHP.

Thats the code triggering the problem:

        $qb = $this->createQueryBuilder('tag');

        $qb1 = $this->getEntityManager()->createQueryBuilder();
        $qb1->from(Timesheet::class, 't')->select('COUNT(tags)')->innerJoin('t.tags', 'tags')->where('tags.id = tag.id');

        $qb->select('tag.id, tag.name, tag.color, tag.visible');
        $qb->addSelect('(' . $qb1->getDQL() . ') as amount'); <= this here causes the endless loop

If I remove the last line (the getDQL() subselect), the issue goes away.

I tried to lower the Doctrine package, tried to lower the level from 9 to 4 and removed the bleeding-edge rules:
Bildschirmfoto 2024-08-29 um 23 47 59

Do you have any idea where/how I could investigate what is going on?

@ondrejmirtes
Copy link
Member

Would be good if you tried to reproduce it here in the test suite.

Also try to bring the environments of your local machine and GitHub Actions closer with these steps, you might be able to reproduce it in both places: https://phpstan.org/blog/phpstan-reports-different-errors-locally-ci-what-should-i-do

@kevinpapst
Copy link
Contributor Author

kevinpapst commented Aug 31, 2024

Thanks, I double checked, but I already follow best practices. Couldn't find anything related in your blog post.

This line triggers the endless loop:

$qb->addSelect('(' . $qb1->getDQL() . ') as amount'); <= this here causes the endless loop

I can remove it and PHPStan works again.

To get rid of the error I can also remove:

    doctrine:
        objectManagerLoader: %rootDir%/../../../tests/phpstan-doctrine.php

And I can replace these lines:

// next line results in endless loop
$qb->addSelect('(' . $qb1->getDQL() . ') as amount');

// fetching the DQL and adding it manually works as expected (but I can't use that)
$qb->addSelect('(SELECT COUNT(tags) FROM App\Entity\Timesheet t INNER JOIN t.tags tags WHERE tags.id = tag.id) as amount');

So the error is likely somewhere in this bridge trying to understand the subselect?!?

The tests not only require mongo, they are also really hard to read and understand.
I'll leave this here, in case someone else stumbles upon this issue as well.

@kevinpapst
Copy link
Contributor Author

Found even more weirdness. This works

        $dql = $qb1->getDQL();
        $qb->addSelect('(' . $dql . ') as amount');

And this causes PHPStan to be blocked until PHP timeout:

        $qb->addSelect('(' . $qb1->getDQL() . ') as amount');

@kevinpapst
Copy link
Contributor Author

Anyway, closing as this seems to be of no interest and/or environment specific.

@kevinpapst
Copy link
Contributor Author

kevinpapst commented Sep 19, 2024

@ondrejmirtes I think this is a deeper issue, I am running into a Segmentation fault now with the above mentioned code piece.

If you check this build, you can see

Run vendor/bin/phpstan analyse -c phpstan.neon --no-progress --error-format=checkstyle | cs2pr
⚠️  Result is incomplete because of severe errors. ⚠️
   Fix these errors first and then re-run PHPStan
   to get all reported errors.
Error: Child process error (exit code 13[9](https://github.com/kimai/kimai/actions/runs/10941537291/job/30376399422#step:12:10)): Segmentation fault (core dumped)  while running parallel worker

Now one commit later the build does not fail anymore on PHPStan. You can see the latest commits and build here to verify it yourself.
Bildschirmfoto 2024-09-19 um 20 41 59

I think there is an issue in PHPStan.

$ composer show|grep phpstan
phpstan/phpdoc-parser               1.30.1   PHPDoc parser with support for nullable, intersection and generic types
phpstan/phpstan                     1.12.4   PHPStan - PHP Static Analysis Tool
phpstan/phpstan-deprecation-rules   1.2.1    PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.
phpstan/phpstan-doctrine            1.5.3    Doctrine extensions for PHPStan
phpstan/phpstan-phpunit             1.4.0    PHPUnit extensions and rules for PHPStan
phpstan/phpstan-strict-rules        1.6.0    Extra strict and opinionated rules for PHPStan
phpstan/phpstan-symfony             1.4.9    Symfony Framework extensions and rules for PHPStan

@kevinpapst kevinpapst reopened this Sep 19, 2024
@kevinpapst kevinpapst changed the title Seeking help with endless loop Segmentation fault - was: Seeking help with endless loop Sep 19, 2024
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

No branches or pull requests

2 participants