|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-11-18 20:59 UTC] kalle@php.net
-Summary: APC/APCu + request_terminate_timeout cause deadlock
+Summary: APCu: request_terminate_timeout cause deadlock
[2021-06-22 12:19 UTC] cmb@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: cmb
[2021-06-22 12:19 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 03:00:01 2025 UTC |
Description: ------------ APC/APCu uses locks to synchronize php-fpm workers, so killing a worker during execution of APC function can cause a deadlock. APC can hang in the apc_... fucntions or when it caches php byte code, so APCu have the same problems and OPcache may also have this bug. Killing php-worker during execution of APC function that writes data, can corrupt APC memory. gdb backtrace: [11.09.2014 16:01:50] pid: 33072 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". 0x00007f2bac266804 in __lll_lock_wait () from /lib64/libpthread.so.0 #0 0x00007f2bac266804 in __lll_lock_wait () from /lib64/libpthread.so.0 #1 0x00007f2bac2620c5 in _L_lock_490 () from /lib64/libpthread.so.0 #2 0x00007f2bac261f1a in pthread_mutex_lock () from /lib64/libpthread.so.0 #3 0x00007f2baa6f2949 in apc_pthreadmutex_lock () from /usr/lib64/php5.3/lib/extensions/no-debug-non-zts-20090626/apc.so #4 0x00007f2baa6eb84f in apc_cache_find_slot () from /usr/lib64/php5.3/lib/extensions/no-debug-non-zts-20090626/apc.so #5 0x00007f2baa6ebab2 in apc_cache_find () from /usr/lib64/php5.3/lib/extensions/no-debug-non-zts-20090626/apc.so #6 0x00007f2baa6f19ae in ?? () from /usr/lib64/php5.3/lib/extensions/no-debug-non-zts-20090626/apc.so #7 0x0000000000661026 in zend_execute_scripts () #8 0x000000000060fc35 in php_execute_script () #9 0x000000000046636a in main () Ways to solve the problem: 1) Implement lock-free hash tables in APC/APCu; 2) Implement careful shut down in php-fpm: php-fpm main process notify worker, that it ran out of time, and then worker correctly stops. Test script: --------------- This test will hang php-fpm. To run it you need "cgi-fcgi", that allows to run php scripts in php-fpm without web server. Create files "apcu.php" and "apcu.sh" and run "apcu.sh". "request_terminate_timeout = 3" in php-fpm.conf # cat /tmp/php-apcu/apcu.php <?php while (1 != 0) { apcu_store ("mykey", "123qwe"); apcu_fetch ("mykey"); } # cat /tmp/php-apcu/apcu.sh #!/bin/sh while [ 0 != 1 ]; do SCRIPT_FILENAME=/tmp/php-apcu/apcu.php \ REQUEST_METHOD=GET \ cgi-fcgi -bind -connect 127.0.0.1:9000 sleep 3 done