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

Stuck on [parsing]... no errors, just totally hangs on certain files... how to #6900

Closed
steinhaug opened this issue Dec 31, 2021 · 12 comments
Closed
Labels

Comments

@steinhaug
Copy link

Bug Report

Subject Stuck on [parsing] .../some/file.php
Rector version Rector 6861ae9

I am having problems when trying to debug where the problem is when Rector is hanging (crashing) on certain files in the projects I am trying to process. I have run ECS on all the files first as a quick fix to atleast make sure the files are up to date in some way, but when running rector with the --debug option I see that it stops on PARSING of some files.

That being said I know that the file in question right now has alot of if statements, so I could rewrite it no problem then again the point of rector I guess was to not do that.

I guess my question is:

  1. Is there a way of debugging the parsing part, so I have some way of getting a hint what to correct in the file ?
  2. How to I ignore certain files in the rector.php config file, so I can skip this file so it doesnt need to get stuck on parsing?

Minimal PHP Code Causing Issue

Rector could not run due to error: The process "'../vendor/bin/rector' 'process' '/var/www/getrector.org/var/demo/7ltw11fmm2z5c0yladmr/rector_analyzed_file.php' '--config' '/var/www/getrector.org/var/demo/7ltw11fmm2z5c0yladmr/rector.php' '--output-format' 'json'" exceeded the timeout of 60 seconds.

@steinhaug steinhaug added the bug label Dec 31, 2021
@internalsystemerror
Copy link

To debug, run rector against just that file and slowly remove portions of the file until rector passes successfully, that should help to narrow down the issue.

As for skipping paths you can check out https://github.com/rectorphp/rector/blob/main/docs/how_to_ignore_rule_or_paths.md.

@TomasVotruba
Copy link
Member

Thank for reporting. This might be many causes.

Could you share minimal reproducible repository?

@steinhaug
Copy link
Author

I upgraded to latest version now, 0.12.10, and I am now working on narrowing down the problem by removing parts of the code of the file. I will post my findings as soon as I have isolated the problem.

@steinhaug
Copy link
Author

steinhaug commented Dec 31, 2021

Well, I have narrowed down the code to this example. This is useless PHP in itself, but atleast the parsing hangs which is my problem.

ews.threads.php.txt

The contents of file is:
`<?php

class swThreads
{
public function sort_comments_in_thread_array($comment, $thread_parentid = 0)
{
if ($thread_parentid) {
if (isset($this->comments['#' . $comment['thread_parentid']])) {
if (in_array('#' . $comment['parentid'], $lv1_keys)) {
if (! $match) {
for ($ii = 0; $ii < count($lv2_keys); $ii++) {
if (! $match3) {
for ($iii = 0; $iii < count($lv3_keys_all); $iii++) {
if (! $match4) {
for ($iiii = 0; $iiii < count($lv4_keys_all); $iiii++) {
if (! $match5) {
for ($i6 = 0; $i6 < count($lv5_keys_all); $i6++) {
if (! $match6) {
for ($i7 = 0; $i7 < count($lv6_keys_all); $i7++) {
if (! $match7) {
for ($i8 = 0; $i8 < count($lv7_keys_all); $i8++) {
if (! $match8) {
for ($i9 = 0; $i9 < count($lv8_keys_all); $i9++) {
if (! $match9) {
for ($i10 = 0; $i10 < count($lv9_keys_all); $i10++) {
if (! $match10) {
for ($i11 = 0; $i11 < count($lv10_keys_all); $i11++) {
if (! $match11) {
for ($i12 = 0; $i12 < count($lv11_keys_all); $i12++) {
if (! $match12) {
for ($i13 = 0; $i13 < count($lv12_keys_all); $i13++) {
if (! $match13) {
for ($i14 = 0; $i14 < count($lv13_keys_all); $i14++) {
// Game over
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return true;
}
}
}

}
`

@TomasVotruba
Copy link
Member

Amazing work, thanks!

Could you put it to demo link? https://getrector.org/demo

@samsonasik
Copy link
Member

It seems got error timeout when paste in getrector.org/demo https://getrector.org/demo/1ec6a582-9588-6b4c-b085-7788681f5100

@samsonasik
Copy link
Member

It seems make hang even without any service registered https://getrector.org/demo/1ec6a5a2-5cbe-63d2-84d7-c57f440713df

@samsonasik
Copy link
Member

The hang seems on the NodeScopeAndMetadataDecorator::decorateNodesFromFile() method:

https://github.com/rectorphp/rector-src/blob/fee8a47d1a627b01bfba2d85293c84692715506a/packages/NodeTypeResolver/NodeScopeAndMetadataDecorator.php#L33

@samsonasik
Copy link
Member

I created issue on phpstan repository phpstan/phpstan#6265

@steinhaug
Copy link
Author

I created issue on phpstan repository phpstan/phpstan#6265

Thank you, I would guess this has to be the problem yes. Luckily I have avoided such code in later years, this is from the days before i grasped recursive programming good enough. Hopefully this is ironed out from phpstan in future releases.

Only goes to show that this code definately needs refactoring :D I will have to do this one manually :D

@samsonasik
Copy link
Member

Ok, I am closing it then as we rely on internal phpstan for this.

@samsonasik
Copy link
Member

Resolved at PHPStan side phpstan/phpstan#6265

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants