[php-src] Issue #10437: Segfault/assertion when using fibers in shutdown function

From: Date: Tue, 24 Jan 2023 18:02:16 +0000
Subject: [php-src] Issue #10437: Segfault/assertion when using fibers in shutdown function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243559@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10437 Author: danog ### Description The following code: ```php <?php set_time_limit(1); register_shutdown_function(function () { Fiber::getCurrent()->suspend(); }); $fiber = new Fiber(function () { while (1); }); $fiber->start(); ``` Resulted in this output on PHP 8.2.1: ``` [daniil@daniil-arch amp]$ php b.php PHP Fatal error: Maximum execution time of 1 second exceeded in /home/daniil/repos/amp/b.php on line 10 Segmentation fault (core dumped) ``` gdb: ``` (gdb) backtrace #0 0x00005555559695d2 in zim_Fiber_suspend (execute_data=<optimized out>, return_value=0x7fffffffbc60) at /usr/src/debug/php/php-8.2.1/Zend/zend_fibers.c:744 #1 0x00005555558edab5 in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (execute_data=0x7ffff4c130f0) at /usr/src/debug/php/php-8.2.1/Zend/zend_vm_execute.h:1842 #2 0x0000555555937438 in execute_ex (ex=<optimized out>) at /usr/src/debug/php/php-8.2.1/Zend/zend_vm_execute.h:55807 #3 0x00005555558b35ee in zend_call_function (fci=<optimized out>, fci_cache=<optimized out>) at /usr/src/debug/php/php-8.2.1/Zend/zend_execute_API.c:930 #4 0x00005555557c0acc in user_shutdown_function_call (zv=<optimized out>) at /usr/src/debug/php/php-8.2.1/ext/standard/basic_functions.c:1646 #5 0x00005555558d5e3a in zend_hash_apply (ht=0x7ffff4c56460, apply_func=0x5555557c0aa0 <user_shutdown_function_call>) at /usr/src/debug/php/php-8.2.1/Zend/zend_hash.c:1990 #6 0x00005555557c163f in php_call_shutdown_functions () at /usr/src/debug/php/php-8.2.1/ext/standard/basic_functions.c:1707 #7 0x0000555555854d26 in php_request_shutdown (dummy=<optimized out>) at /usr/src/debug/php/php-8.2.1/main/main.c:1818 #8 0x00005555559aab2d in do_cli (argc=2, argv=0x5555568377c0) at /usr/src/debug/php/php-8.2.1/sapi/cli/php_cli.c:1135 #9 0x0000555555643bbb in main (argc=2, argv=<optimized out>) at /usr/src/debug/php/php-8.2.1/sapi/cli/php_cli.c:1333 (gdb) zbacktrace [0x7ffff4c13150] Fiber->suspend() [internal function] [0x7ffff4c130f0] {closure}() /home/daniil/repos/amp/b.php:6 ``` Resulted in this output on PHP 68381457cc5370935bc7c69eeeac772be255174e (dev build): ``` [daniil@daniil-arch amp]$ /home/daniil/repos/php-src/sapi/cli/php b.php PHP Fatal error: Maximum execution time of 1 second exceeded in /home/daniil/repos/amp/b.php on line 10 php: /home/daniil/repos/php-src/Zend/zend_fibers.c:849: zim_Fiber_suspend: Assertion `fiber->context.status == ZEND_FIBER_STATUS_RUNNING || fiber->context.status == ZEND_FIBER_STATUS_SUSPENDED' failed. Aborted (core dumped) ``` gdb: ``` (gdb) backtrace #0 __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44 #1 0x00007ffff7a7e6b3 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78 #2 0x00007ffff7a2e938 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26 #3 0x00007ffff7a1853d in __GI_abort () at abort.c:79 #4 0x00007ffff7a1845c in __assert_fail_base (fmt=0x7ffff7b92a50 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x5555566c4f10 "fiber->context.status == ZEND_FIBER_STATUS_RUNNING || fiber->context.status == ZEND_FIBER_STATUS_SUSPENDED", file=0x5555566c49c0 "/home/daniil/repos/php-src/Zend/zend_fibers.c", line=849, function=<optimized out>) at assert.c:92 #5 0x00007ffff7a27486 in __GI___assert_fail (assertion=0x5555566c4f10 "fiber->context.status == ZEND_FIBER_STATUS_RUNNING || fiber->context.status == ZEND_FIBER_STATUS_SUSPENDED", file=0x5555566c49c0 "/home/daniil/repos/php-src/Zend/zend_fibers.c", line=849, function=0x5555566c51f0 <__PRETTY_FUNCTION__.4> "zim_Fiber_suspend") at assert.c:101 #6 0x0000555555b93869 in zim_Fiber_suspend (execute_data=0x7ffff52161c0, return_value=0x7fffffffbaa0) at /home/daniil/repos/php-src/Zend/zend_fibers.c:849 #7 0x0000555555acb820 in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER () at /home/daniil/repos/php-src/Zend/zend_vm_execute.h:1842 #8 0x0000555555b42346 in execute_ex (ex=0x7ffff5216150) at /home/daniil/repos/php-src/Zend/zend_vm_execute.h:56061 #9 0x0000555555a6d29c in zend_call_function (fci=0x7ffff525a1e0, fci_cache=0x7ffff525a220) at /home/daniil/repos/php-src/Zend/zend_execute_API.c:938 #10 0x00005555558fabb5 in user_shutdown_function_call (zv=0x7ffff525f188) at /home/daniil/repos/php-src/ext/standard/basic_functions.c:1640 #11 0x0000555555aa3c1a in zend_hash_apply (ht=0x7ffff525ba80, apply_func=0x5555558fab6c <user_shutdown_function_call>) at /home/daniil/repos/php-src/Zend/zend_hash.c:2000 #12 0x00005555558fae4f in php_call_shutdown_functions () at /home/daniil/repos/php-src/ext/standard/basic_functions.c:1701 #13 0x00005555559df2f5 in php_request_shutdown (dummy=0x0) at /home/daniil/repos/php-src/main/main.c:1820 #14 0x0000555555c05f8e in do_cli (argc=2, argv=0x555556a387c0) at /home/daniil/repos/php-src/sapi/cli/php_cli.c:1135 #15 0x0000555555c06427 in main (argc=2, argv=0x555556a387c0) at /home/daniil/repos/php-src/sapi/cli/php_cli.c:1333 (gdb) zbacktrace [0x7ffff52161c0] Fiber->suspend() [internal function] [0x7ffff5216150] {closure}() /home/daniil/repos/amp/b.php:6 ``` But I expected this output instead: No segmentation fault ### PHP Version PHP 8.2.1 ### Operating System Arch linux

« previous php.bugs (#243559) next »