You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Segmentation fault when generating composer autoload with 50k+ classes #11795
Running composer dumpautoload --optimize-autoloader twice on a large codebase (50k+ classes it seems) with OPCache enabled in Docker results in a segmentation fault. Changing OPCache settings doesn't seem to do anything.
This is reproducible on a x86_64, but is not reproducible on ARM MacBook. PHP 8.1.9 is also affected.
This can also be reproduced with php -d opcache.enable_cli=1 vendor/composer/autoload_classmap.php, no need to wait for the autoloader (can be very slow with a debug build).
I raised the 10000 and the cycle error is gone.
I can reproduce it in the Docker container reliably.
I can only reproduce it on a debug build if I lower the stack limit using ulimit -s, and I believe I was right:
==463345==ERROR: AddressSanitizer: stack-overflow on address 0x7ffcbe402ffc (pc 0x55f4a810ce86 bp 0x7ffcbe403030 sp 0x7ffcbe402fe0 T0)
#0 0x55f4a810ce86 in zend_ssa_check_scc_var /run/media/niels/MoreData/php-src/Zend/Optimizer/zend_inference.c:176
#1 0x55f4a810df39 in zend_ssa_check_scc_var /run/media/niels/MoreData/php-src/Zend/Optimizer/zend_inference.c:185
#2 0x55f4a810df39 in zend_ssa_check_scc_var /run/media/niels/MoreData/php-src/Zend/Optimizer/zend_inference.c:185
...
repeat that a couple of hundred times...
It's because the SCC algorithm is recursive instead of iterative.
This is actually a duplicate of GH-11240, and could be fixed with #11272. But Dmitry had some remarks that I should use a reference implementation instead of creating an iterative version myself.
I can resume work on that PR probably, or someone else can too if they want (I'm kinda deep down in ext/dom troubles). There's links in the comment section to relevant papers & implementations. I believe the implementation I wrote can be adapted fairly easily to those reference algorithms since they have the same core idea: going up and down the DFS with a flag basically.
@nielsdos your approach to SCC algorithm conversion might be right, but I wouldn't harry to fix it.
The application of the original algorithm might be not efficient in the first place.
Not that at the moment of SCC identification we already identified control loops and reducibility (or irreducibility).
So, we may evaluate only a part of the data flow graph that nests in the loops.
Activity
iluuu1994 commentedon Jul 25, 2023
I guess @nielsdos beat me to it 🙂 But I can reproduce this:
This can also be reproduced with
php -d opcache.enable_cli=1 vendor/composer/autoload_classmap.php, no need to wait for the autoloader (can be very slow with a debug build).ndossche commentedon Jul 25, 2023
Race ya ;) /jk
I got the same cycle error, but that might be a red herring though because it assumes that > 10000 uses means a cycle:
there are more than that nr of uses here.
I have a feeling it's actually the strongly connected components algorithm doing a stackoverflow.
ndossche commentedon Jul 25, 2023
I raised the 10000 and the cycle error is gone.
I can reproduce it in the Docker container reliably.
I can only reproduce it on a debug build if I lower the stack limit using
ulimit -s, and I believe I was right:repeat that a couple of hundred times...
It's because the SCC algorithm is recursive instead of iterative.
This is actually a duplicate of GH-11240, and could be fixed with #11272. But Dmitry had some remarks that I should use a reference implementation instead of creating an iterative version myself.
I can resume work on that PR probably, or someone else can too if they want (I'm kinda deep down in ext/dom troubles). There's links in the comment section to relevant papers & implementations. I believe the implementation I wrote can be adapted fairly easily to those reference algorithms since they have the same core idea: going up and down the DFS with a flag basically.
dstogov commentedon Jul 31, 2023
@nielsdos your approach to SCC algorithm conversion might be right, but I wouldn't harry to fix it.
The application of the original algorithm might be not efficient in the first place.
Not that at the moment of SCC identification we already identified control loops and reducibility (or irreducibility).
So, we may evaluate only a part of the data flow graph that nests in the loops.
Backport implementation of iterative Pearce's SCC finding algoritm (#…
danog commentedon Dec 13, 2023
Might be not completely fixed, see #12953