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

Rector Halts and Leaks Memory During Interaction of AddDefaultValueForUndefinedVariable (5.6), IfToSpaceship (7.0), and ClosureToArrowFunction (7.4) #7904

Closed
Kenneth-Sills opened this issue Apr 28, 2023 · 1 comment · Fixed by rectorphp/rector-src#3701
Assignees
Labels

Comments

@Kenneth-Sills
Copy link

Kenneth-Sills commented Apr 28, 2023

Bug Report

Subject Details
Rector version Tested on 0.15.18, 0.15.24, and 0.15.25

When using the following three rules together, Rector halts upon encountering a uasort that satisfies IfToSpaceshipRector, then begins rapidly consuming memory until it hits the limit or the host crashes:

  • PHP 5.6: AddDefaultValueForUndefinedVariableRector
  • PHP 7.0: IfToSpaceshipRector
  • PHP 7.4: ClosureToArrowFunctionRector

This was initially discovered when using LevelSetList::UP_TO_PHP_82.

EDIT: It may also be note-worthy that when this happens, the user can Ctrl+C to end the process. When running again without --clear-cache, the issue will not re-occur in the same file but the rules will be skipped. The issue will re-occur if another file has the same issue or if --clear-cache is provided.

Minimal PHP Code Causing Issue

https://getrector.com/demo/dd221fce-626a-4664-9f07-c16fc5ff68aa

Based on this demo, the issue only seems to occur when the IfToSpaceshipRector and ClosureToArrowFunction interact as a function parameter. Individually, all rules work normally. When not nested inside a function call, the interaction of the latter two rules still works as expected.

I'm not sure why AddDefaultValueForUndefinedVariableRector is required for reproduction, but removing it or adding it to the skip list fixes the crash.

Expected Behaviour

The minimum error demo above should be refactored to:

<?php

final class DemoFile
{
    public function run()
    {
        uasort([], fn ($a, $b) => $a <=> $b;
    }
}

I appreciate your time!

@samsonasik samsonasik self-assigned this Apr 28, 2023
@yguedidi
Copy link

EDIT: It may also be note-worthy that when this happens, the user can Ctrl+C to end the process. When running again without --clear-cache, the issue will not re-occur in the same file but the rules will be skipped. The issue will re-occur if another file has the same issue or if --clear-cache is provided.

@Kenneth-Sills it's because the file is added to the cache in its state before being traversed by the different enabled rectors.
There is the following in progress work that will fix that: rectorphp/rector-src#3614

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