Skip to content

Commit

Permalink
Try to quit the child process only after internal errors were account…
Browse files Browse the repository at this point in the history
…ed for
  • Loading branch information
ondrejmirtes committed Oct 11, 2024
1 parent 2e8b260 commit dcd69eb
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ jobs:
cd e2e/bad-exclude-paths
OUTPUT=$(../../bin/phpstan analyse -c ignoreReportUnmatchedFalse.neon)
echo "$OUTPUT"
- script: |
cd e2e/bug-11826
composer install
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan")
echo "$OUTPUT"
../bashunit -a contains 'Child process error (exit code 255): PHP Fatal error' "$OUTPUT"
../bashunit -a contains 'Result is incomplete because of severe errors.' "$OUTPUT"
steps:
- name: "Checkout"
Expand Down
2 changes: 2 additions & 0 deletions e2e/bug-11826/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor
/composer.lock
8 changes: 8 additions & 0 deletions e2e/bug-11826/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"autoload": {
"psr-4": {
"App\\": "src/",
"Rules\\": "rules/"
}
}
}
8 changes: 8 additions & 0 deletions e2e/bug-11826/phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: 9
paths:
- src
- rules

rules:
- Rules\DummyRule
35 changes: 35 additions & 0 deletions e2e/bug-11826/rules/DummyRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types = 1);

namespace Rules;

use App\FatalErrorWhenAutoloaded;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassNode;
use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Rule;

/**
* @implements Rule<InClassNode>
*/
class DummyRule implements Rule
{

public function getNodeType(): string
{
return InClassNode::class;
}

/**
* @param InClassNode $node
* @return list<IdentifierRuleError>
*/
public function processNode(
Node $node,
Scope $scope,
): array
{
return [FatalErrorWhenAutoloaded::AUTOLOAD];
}

}
11 changes: 11 additions & 0 deletions e2e/bug-11826/src/FatalErrorWhenAutoloaded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php declare(strict_types = 1);

namespace App;

interface FatalErrorWhenAutoloaded
{

public const AUTOLOAD = 'autoload';
public const CLASS = 'error';

}
6 changes: 5 additions & 1 deletion src/Parallel/ParallelAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,12 @@ public function analyse(
}
$someChildEnded = true;

$this->processPool->tryQuitProcess($processIdentifier);
if ($exitCode === 0) {
$this->processPool->tryQuitProcess($processIdentifier);
return;
}
if ($exitCode === null) {
$this->processPool->tryQuitProcess($processIdentifier);
return;
}

Expand All @@ -294,6 +295,7 @@ public function analyse(
continue;
}

$this->processPool->tryQuitProcess($processIdentifier);
return;
}
$internalErrors[] = new InternalError(sprintf(
Expand All @@ -303,11 +305,13 @@ public function analyse(
'Increase your memory limit in php.ini or run PHPStan with --memory-limit CLI option.',
), 'running parallel worker', [], null, false);
$internalErrorsCount++;
$this->processPool->tryQuitProcess($processIdentifier);
return;
}

$internalErrors[] = new InternalError(sprintf('Child process error (exit code %d): %s', $exitCode, $output), 'running parallel worker', [], null, true);
$internalErrorsCount++;
$this->processPool->tryQuitProcess($processIdentifier);
});
$this->processPool->attachProcess($processIdentifier, $process);
}
Expand Down

0 comments on commit dcd69eb

Please sign in to comment.