krakjoe / parallel

A succinct parallel concurrency API for PHP8
Other
1.44k stars 94 forks source link

Segfault when using opcache and bootstrap file #266

Open JanTvrdik opened 1 year ago

JanTvrdik commented 1 year ago

Full isolated reproduction example: https://github.com/JanTvrdik/php-ext-parallel-segfault

Step to reproduce the segfault

Run the following command:

docker build . -t segfault && docker run --rm -ti segfault

Known requirements to trigger segfault

GDB output

(gdb) run run.php
Starting program: /usr/local/bin/php run.php
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7f6b10723700 (LWP 454)]
[New Thread 0x7f6b0fbff700 (LWP 455)]
[New Thread 0x7f6b0efff700 (LWP 456)]
[New Thread 0x7f6b0e3ff700 (LWP 457)]
[New Thread 0x7f6b0d7ff700 (LWP 458)]
[New Thread 0x7f6b0cbff700 (LWP 459)]

Thread 6 "php" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f6b0d7ff700 (LWP 458)]
0x000055bf0f607297 in ?? ()
(gdb) bt
#0  0x000055bf0f607297 in ?? ()
#1  0x000055bf0f609a06 in zend_do_link_class ()
#2  0x000055bf0f547c43 in zend_bind_class_in_slot ()
#3  0x000055bf0f547d6e in do_bind_class ()
#4  0x000055bf0f5a63d5 in ?? ()
#5  0x000055bf0f5da3f5 in execute_ex ()
#6  0x000055bf0f5616a4 in zend_call_function ()
#7  0x000055bf0f561b4d in zend_call_known_function ()
#8  0x000055bf0f432c9a in ?? ()
#9  0x000055bf0f560755 in zend_lookup_class_ex ()
#10 0x000055bf0f58aa85 in ?? ()
#11 0x000055bf0f5dd308 in execute_ex ()
#12 0x00007f6b1125dbd7 in php_parallel_scheduler_run (frame=0x7f6b0cc14020, runtime=<optimized out>) at /tmp/pear/temp/parallel/src/scheduler.c:316
#13 0x00007f6b1125e1bd in php_parallel_thread (arg=0x7f6b1105c5a0) at /tmp/pear/temp/parallel/src/scheduler.c:486
#14 0x00007f6b146f1ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#15 0x00007f6b13e3ea2f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
JanTvrdik commented 1 year ago

Running the code with PHP 8.1 does result in the same fatal error, but it does not segfault.

Fatal error: Environment cannot implement - it is not an interface in /src/Environment.php on line 3

Running the code with PHP 8.0 works without any issues.

michael-rubel commented 10 months ago

Very strange. I had a similar issue on PHP 8.2. I tried to disable opcache.enable_cli for a while. Applied a higher memory limit (512M), then enabled it back and it started working like a charm.

realFlowControl commented 2 months ago

Hey @JanTvrdik, thanks for creating a reproducer in Docker. I tried to run this but could not reproduce, not on MacOS and not in your docker container. It could be that this is because I'm running on ARM64. Can you double check if you can still reproduce the issue?

JanTvrdik commented 2 months ago

Yes. This is the ouput I get today:

OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
Segmentation fault
Command failed on iteration 20
JanTvrdik commented 2 months ago

I also tried GitHub Codespaces, and it took a lot longer to fail, but eventually it did

https://codespaces.new/JanTvrdik/php-ext-parallel-segfault

Segmentation fault (core dumped)
Command failed on iteration 862
hschimpf commented 1 month ago

I have a similar behavior, when running on PHP 8.0 all works flawlessly, but the same process on PHP version 8.1 and prior does segfault ^1.

Tried changing some values on the PHP configuration (opcache, jit, buffer size, ...) but didn't found any solution.