squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

RuntimeException: Undefined variable: childOutput in squizlabs/php_codesniffer/src/Runner.php on line 705 #2304

Closed yoeunes closed 5 years ago

yoeunes commented 5 years ago

Description

I get this exception when i run phpcs using a parallel value greater than 1

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined variable: childOutput in /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php on line 705 in /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php:562
Stack trace:
#0 /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(705): PHP_CodeSniffer\Runner->handleErrors(8, 'Undefined varia...', '/Users/yoeunes/...', 705, Array)
#1 /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(502): PHP_CodeSniffer\Runner->processChildProcs(Array)
#2 /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
#3 /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#4 {main}
  thrown in /Users/yoeunes/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php on line 562

this is my phpcs.xml file:

<?xml version="1.0"?>
<ruleset name="coding standard">
    <description>coding standard</description>

    <arg name="extensions" value="php"/>

    <arg name="parallel" value="2"/>

    <file>src</file>

    <rule ref="PSR2" />

</ruleset>
jrfnl commented 5 years ago

I tested with parentheses as well, but it didn't work either, thing is, on MacOS, any statement with preg_match within a forked child process results in segmentation fault, no matter what you put inside.

So, if I understand you correctly, that basically just confirms that this is an issue which needs to be solved in PHP Core (or possibly MacOS), not in PHP userland code.

A search of the PHP bug tracker yielded this issue which I believe is the closest match: https://bugs.php.net/bug.php?id=77260

@gagan0123 It might help get the issue resolved if you (or someone else who can reproduce the issue) would add details of the findings from this ticket to that thread.

gsherwood commented 5 years ago

Currently child processes in PHPCS are failing at https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Util/Common.php#L143

Just a note that during my debugging yesterday, my child processes were not directly failing here. I was able to echo content after the preg_match had completed and have that successfully output to screen for the child process. I could also exit after the preg_match and have the child process exit normally. But by the time the function had returned its value back to the caller, the process was dead.

I've been unable to replicate the issue in a test script, otherwise I'd report it.