PHP_CodeSniffer: RuntimeException: Undefined variable: childOutput in squizlabs/php_codesniffer/src/Runner.php on line 705
- phpcs version : 3.3.2
- php version: 7.2 and 7.3
- operating system: osx
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>
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 14
- Comments: 52 (25 by maintainers)
Commits related to this issue
- Fixed an issue where the PCRE JIT on PHP 7.3 caused PHPCS to die when using the parallel option (ref #2304) — committed to squizlabs/PHP_CodeSniffer by gsherwood 5 years ago
I ended up just disabling the pcre jit for PHPCS (c09a4e1a2f3f6fe4a628e72b5e61ad35b309ed02). I couldn’t figure out why the processes were dying and why a simple regex would kill it.
I’ve also changed the process handling code so that PHPCS will die with a more specific error message rather than just an undefined var error.
If anyone is able to test this fix, I’d be very grateful. Or even just disabling the jit in your php.ini to confirm that is the cause for you as well.
Yep, crash in
PHP 7.3.1 (cli) (built: Jan 10 2019 13:15:37) ( NTS )(homebrew)Actually that may be a false positive, it started happening again after the first run, so upon php upgrade the first run was ok, the second and all since then, not.
I have the same issue on mac using
brew install phpversion 7.3.1:Downgrading back to v7.1.23 works correctly
I have the same problem with php 7.3. One Project ist okey and another have the problem. I can it reproduce only on mac and on alpine is fine.
Thanks for confirming it works on Windows 😃
I tested with parentheses as well, but it didn’t work either, thing is, on MacOS, any statement with
preg_matchwithin a forked child process results in segmentation fault, no matter what you put inside.Learnt a lot while debugging this issue, thanks to @yoeunes for bringing this up 👍
@gagan0123 Oh wow! Well done with the debugging!
If it helps: I was never able to reproduce the issue on Windows, so can confirm, based on one user testing, that things work fine on Windows.
Just had a quick look at that regex, even though it may not be the actual issue. I know PCRE2 is stricter regarding syntax and the
|should really be within parentheses, so I’d be interested to see if changing the line to the below would make a difference:Thanks @GaryJones and @gagan0123 for testing. I’m going to close this so this change can be released in 3.4.2.
If anyone is continuing to have issues that this fix does not resolve, then it is likely to be a different problem and a new issue should be opened. If anyone has any idea how to get the parallel option working with the jit, please open an issue to discuss that as well.
Thanks to everyone who provided info to help track this down.
It Works 😃
@gsherwood Thanks for being so patient with this bug and helping us out
🤔 Still wondering why it works with JIT enabled on PHP 7.2 but not on PHP 7.3
@GaryJones Thanks for testing that for me.
I can confirm that turning off JIT for PHP 7.3, allows PHPCS to run with parallel > 1.
I’ve managed to replicate this with a new brew installed version of PHP 7.3.4. Comparing that to my known working versions of 7.3, I’ve found that this php.ini setting appears to be the problem:
Note that it is commented out, but the default value is obviously to enable this. Disabling this fixes the problems for me, and reflects what my working 7.3 installs have already done by default:
I debugged PHPCS as far as I could to determine why the child processes were failing, but it looked like the process just died between function calls. But this is a regex extension and I did notice that leaving the EOL char of files empty did allow the script to continue longer, but die from other reasons.
I’ll keep looking into this to see if there is a particular regex that the jit is breaking. If I can’t find one, I’ll see if I can disable or detect this ini setting during a PHPCS run, or just detect that the child process has died and fail the entire run (means you wont be able to use the parallel option with the jit enabled).
If it helps I had the same issue in PHP 7.3.1, but it stopped when I upgraded to PHP 7.3.2.