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

Parallel runner not fixing any files #8014

Open
2 tasks done
X-Coder264 opened this issue May 15, 2024 · 26 comments
Open
2 tasks done

Parallel runner not fixing any files #8014

X-Coder264 opened this issue May 15, 2024 · 26 comments
Labels
kind/bug status/input required For the issue to be confirmed or the PR to be process; additional input of the author is required topic/parallel Issues related to parallel runner

Comments

@X-Coder264
Copy link

Problem description

After enabling the parallel runner no files are being fixed anymore. It seems like CS fixer just finishes the process with the progress bar still being at 0%.

Minimal reproducer

$finder = (new PhpCsFixer\Finder())
    ->in(\dirname(__DIR__, 3) . '/src')
;

return (new PhpCsFixer\Config())
    //->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
    ->setRules(
        [
            'nullable_type_declaration' => ['syntax' => 'union'],
        ],
    )
    ->setRiskyAllowed(true)
    ->setLineEnding("\n")
    ->setIndent('    ')
    ->setFinder($finder)
;

This is a simplified version of the config that I have that reproduces this problem and I've changed on purpose one method in my src folder to abstract protected function getType(): ?DocumentType;

After the fixer runs I'd expect to get abstract protected function getType(): null|DocumentType; as a result.
Running php-cs-fixer fix --no-interaction --diff -vvv --using-cache=no with this config without the parallel runner results in the file being fixed:

PHP CS Fixer 3.57.0 (5c90224) 7th Gear by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.2.18
Running analysis on 1 core sequentially.
You can enable parallel runner and speed up the analysis! Please see usage docs for more information.
Loaded config default from "./app/tools/php-cs-fixer/config.php".
 6703/6703 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

   1) src/foo.php (nullable_type_declaration)
      ---------- begin diff ----------
--- /srv/app/src/foo.php
+++ /srv/app/src/foo.php
@@ -29,7 +29,7 @@
 
-    abstract protected function getType(): ?DocumentType;
+    abstract protected function getType(): null|DocumentType;


      ----------- end diff -----------


Fixed 1 of 6703 files in 12.973 seconds, 100.000 MB memory used

If I enable the parallel runner the file does not get fixed and the output is:

PHP CS Fixer 3.57.0 (5c90224) 7th Gear by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.2.18
Running analysis on 20 cores with 10 files per process.
Parallel runner is an experimental feature and may be unstable, use it at your own risk. Feedback highly appreciated!
Loaded config default from "./app/tools/php-cs-fixer/config.php".
    0/6703 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
Fixed 0 of 6703 files in 0.530 seconds, 78.000 MB memory used

Fixer version

3.57.0

PHP version

8.2.18

How do you run Fixer?

Composer Shim package (binary only)

Contribution Checks

  • I have verified if this problem was already reported
  • I am familiar with "Feature or bug?"
@X-Coder264 X-Coder264 added kind/bug status/to verify issue needs to be confirmed or analysed to continue labels May 15, 2024
@Wirone Wirone added the topic/parallel Issues related to parallel runner label May 15, 2024
@Wirone
Copy link
Member

Wirone commented May 15, 2024

@X-Coder264 could it be related to #8013, or you don't use --path-mode=intersection?

@X-Coder264
Copy link
Author

I don't use --path-mode=intersection.

@keradus
Copy link
Member

keradus commented May 15, 2024

I will assume 3.57.1 is not fixing the issue.

Can you provide similar reproduce method to following ?

cd $(mktemp -d)
git clone https://github.com/verfriemelt-dot-org/wrapped . ## your repo
git checkout dae18e31aa003c818abe359f0e18378f89e19e12 ## your commit/branch
composer install
php-cs-fixer fix -vvv --using-cache=no --path-mode=intersection -- .php-cs-fixer.dist.php ## your command

@X-Coder264
Copy link
Author

@keradus You assumed correctly, 3.57.1 is not fixing the issue for me.

The weird thing is I've tried the parallel runner on another project (that one doesn't use php-cs-fixer/shim though, it uses friendsofphp/php-cs-fixer) and it's working just fine there so I'm really confused as to what could be the problem here.

I'll remove the shim and install the non shim version tomorrow and see if that changes anything. If it doesn't I'll try to see what's going on with Xdebug if I'll have the time.

@X-Coder264
Copy link
Author

X-Coder264 commented May 16, 2024

Ok, I found the difference between the config of those two projects.

In the project in which the parallel runner does not work at all there are these two lines at the top of the CS fixer config file:

require \dirname(__DIR__, 3) . '/vendor/autoload.php';
require \dirname(__DIR__, 3) . '/vendor/kubawerlos/php-cs-fixer-custom-fixers/bootstrap.php';

If I just comment out the first line along with all the custom fixers that are configured like PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer::name() => true, then the parallel runner starts working just fine. I'm not sure why does requiring the autoload.php file affect the runner? 🤔

@keradus
Copy link
Member

keradus commented May 16, 2024

ideally, please share example repo to reproduce (you do not need to expose whole source code you have, just minimum reproducable example). For now, you are only one who can evidence and debug the issue.

#8014 (comment)

@keradus keradus added the status/input required For the issue to be confirmed or the PR to be process; additional input of the author is required label May 16, 2024
@Wirone
Copy link
Member

Wirone commented May 16, 2024

The weird thing is I've tried the parallel runner on another project (that one doesn't use php-cs-fixer/shim though, it uses friendsofphp/php-cs-fixer) and it's working just fine there so I'm really confused as to what could be the problem here.

This is something I noticed right after you reported the problem (using shim package), this should be verified in the first place. If I remember correctly I've been testing parallel runner using locally built PHAR file, but never tested shim installation.

@X-Coder264
Copy link
Author

@keradus I've been trying to create a minimal reproducer but so far I was unable to do so.

All I can confirm for now is that if I remove php-cs-fixer/shim and require friendsofphp/php-cs-fixer instead then the parallel runner works fine.

@keradus
Copy link
Member

keradus commented May 17, 2024

I failed to reproduce with shim. if you cannot create minimal reproducer on your side, are you OK to grant temporary access to repo you experience the issue ?

@X-Coder264
Copy link
Author

Sorry, I don't have the permissions on Github to give access to the project repository even if I wanted to.

@keradus
Copy link
Member

keradus commented May 19, 2024

are you able to create new repo with very limited content, that is allowing to reproduce issue you are facing ?

@sebastiaanluca
Copy link

Just chiming in here for what it's worth, but we're having the exact same issue. Works fine at the moment without parallel checks, but does nothing when enabled.

I can simplify our config to the following:

<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$rules = [
    'blank_line_after_opening_tag' => true,
    'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters']],
];

$finder = Finder::create()->in([__DIR__.'/config']);

return (new Config)
    ->setRules($rules)
    ->setFinder($finder)
    ->setUsingCache(false)
    ->setParallelConfig(ParallelConfigFactory::detect());

Which shows the progress bar but changes nothing to the files (for which I used the wrong code style for the 2 rules above):

PHP CS Fixer 3.57.1 7th Gear by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.3.7
Running analysis on 8 cores with 10 files per process.
Parallel runner is an experimental feature and may be unstable, use it at your own risk. Feedback highly appreciated!
Loaded config default from "redacted/.php-cs-fixer.dist.php".
Using cache file ".php-cs-fixer.cache".
  0/61 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
Fixed 0 of 61 files in 0.104 seconds, 28.000 MB memory used

Will try to recreate a reproducible example later.

@enp-mrygiel
Copy link

For what it's worth - I'm facing the exact same issue.
Tested using 3.57.2

image

@Wirone Wirone removed the status/to verify issue needs to be confirmed or analysed to continue label May 21, 2024
@Wirone
Copy link
Member

Wirone commented May 21, 2024

@sebastiaanluca @enp-mrygiel how do you install Fixer? Shim package or something different?

@sebastiaanluca
Copy link

@sebastiaanluca @enp-mrygiel how do you install Fixer? Shim package or something different?

Not sure what the shim package is, but just composer require --dev friendsofphp/php-cs-fixer.

@potsky
Copy link

potsky commented May 24, 2024

Hi!
We have the same error but only when specifying a folder in command line:

  • vendor/bin/php-cs-fixer fix app/Models --config=.php-cs-fixer.dist.php -v --using-cache=no fixes nothing
  • vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=no works and fix files in app/Models

The output of the first command is:

vendor/bin/php-cs-fixer fix app/Models --config=.php-cs-fixer.dist.php -v --using-cache=no
PHP CS Fixer 3.57.1 7th Gear by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.3.7
Running analysis on 12 cores with 10 files per process.
Parallel runner is an experimental feature and may be unstable, use it at your own risk. Feedback highly appreciated!
Loaded config default from ".php-cs-fixer.dist.php".
Paths from configuration file have been overridden by paths provided as command arguments.
  0/62 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
Fixed 0 of 62 files in 0.109 seconds, 26.000 MB memory used

@Wirone
Copy link
Member

Wirone commented May 24, 2024

Interesting, but I still can't reproduce it locally. When I run parallel analysis on Fixer's repo with a directory path as CLI argument, it's running correctly. Please guys, can anyone extract minimal reproducer repo so we can take a look what's happening there?

@potsky
Copy link

potsky commented May 24, 2024

Interesting, but I still can't reproduce it locally. When I run parallel analysis on Fixer's repo with a directory path as CLI argument, it's running correctly. Please guys, can anyone extract minimal reproducer repo so we can take a look what's happening there?

Just more context: in fact it works on Apple M1 with 10 CPUs and it fails on Apple M3 with 12 cores. Even if we reduce (on M3) the number of cores in docker to 10 or less, it always uses 12 cores.

Here is the output on an M1 which always works:

vendor/bin/php-cs-fixer fix app/Models --config=.php-cs-fixer.dist.php -v --using-cache=no
PHP CS Fixer 3.57.2 7th Gear by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.3.7
Running analysis on 10 cores with 10 files per process.
Parallel runner is an experimental feature and may be unstable, use it at your own risk. Feedback highly appreciated!
Loaded config default from ".php-cs-fixer.dist.php".
Paths from configuration file have been overridden by paths provided as command arguments.
 62/62 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

   1) app/Models/Social.php (phpdoc_no_alias_tag, fully_qualified_strict_types, phpdoc_types_order, phpdoc_separation)
....
  52) app/Models/Group.php (phpdoc_no_alias_tag, fully_qualified_strict_types, phpdoc_types_order, phpdoc_separation)

Hope it can help...

@Wirone
Copy link
Member

Wirone commented May 24, 2024

Interesting... I have M1 and even if I explicitly configure more processes than I have available cores, it still works...

./php-cs-fixer check
PHP CS Fixer 3.57.3-DEV 7th Gear by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.3.4
Running analysis on 15 cores with 50 files per process.
Parallel runner is an experimental feature and may be unstable, use it at your own risk. Feedback highly appreciated!
Loaded config default from "/Volumes/Projects/~Github/PHP-CS-Fixer/PHP-CS-Fixer/.php-cs-fixer.php".
 1118/1118 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


Found 0 of 1118 files that can be fixed in 12.627 seconds, 22.00 MB memory use

@potsky do you use CPU auto-detection? Can you test on M3 with explicit ->setParallelConfig(new ParallelConfig(5))?

@potsky
Copy link

potsky commented May 24, 2024

Yes @Wirone we use ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()) and everything is fine on my M1.
I will try to set the number of cores on a M3 and I will tell you.

@potsky
Copy link

potsky commented May 24, 2024

@Wirone We have tested on a M3 with ->setParallelConfig(new ParallelConfig(5) and this is the same problem :-(

@keradus
Copy link
Member

keradus commented Jun 1, 2024

@potsky , you think you can provide sth?

Please guys, can anyone extract minimal reproducer repo so we can take a look what's happening there?

@potsky
Copy link

potsky commented Jun 2, 2024

I have a M1 so I cannot provide anything directly, I will check tomorrow with my colleague @sylouuu if he can test some things and provide more information

@julienarcin
Copy link

julienarcin commented Jun 3, 2024

I have the same behavior.

The weird thing is that's it's working well inside PHPStorm terminal, but stuck at 0% when using iTerm2.

Both with the same codebase, with zsh and the same PHP version.
And on the same machine (Macbook Pro Intel Core i9).

It doesn't seem hardware-related, at least on my side. 🤷‍♂️

@potsky
Copy link

potsky commented Jun 3, 2024

I have the same behavior.

The weird thing is that's it's working well inside PHPStorm terminal, but stuck at 0% when using iTerm2.

Both with the same codebase, with zsh and the same PHP version. And on the same machine (Macbook Pro Intel Core i9).

It doesn't seem hardware-related, at least on my side. 🤷‍♂️

Really interesting 🤔

It works on my Mac M1 with iTerm2 terminal.
It falls on the Mac M3 with Warp terminal of my colleague.

@Wirone
Copy link
Member

Wirone commented Jun 3, 2024

In our CI it works on PHP 7.4-8.4, on Linux, MacOS and Windows. Locally I use parallel runner on MacOS (M1) within iTerm2 and PHPStorm's terminal (the new one, but also the old one which just spawns the same ZSH session as iTerm2). Tested also with built-in Terminal (v2.14), also works properly. It works for files configured in the config file, but also when I set file/dir as a CLI command argument... I don't have any reproducer currently and can't help 🙁.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug status/input required For the issue to be confirmed or the PR to be process; additional input of the author is required topic/parallel Issues related to parallel runner
Projects
None yet
Development

No branches or pull requests

7 participants