|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69048 APCu: request_terminate_timeout cause deadlock
Submitted: 2015-02-13 00:34 UTC Modified: 2021-06-22 12:19 UTC
Avg. Score:4.7 ± 0.6
Reproduced:8 of 9 (88.9%)
Same Version:4 (50.0%)
Same OS:7 (87.5%)
From: fadimko at gmail dot com Assigned: cmb (profile)
Status: Closed Package: APC (PECL)
PHP Version: 5.5.21 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
42 - 21 = ?
Subscribe to this entry?

 [2015-02-13 00:34 UTC] fadimko at gmail dot com
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/".
0x00007f2bac266804 in __lll_lock_wait () from /lib64/
#0  0x00007f2bac266804 in __lll_lock_wait () from /lib64/
#1  0x00007f2bac2620c5 in _L_lock_490 () from /lib64/
#2  0x00007f2bac261f1a in pthread_mutex_lock () from /lib64/
#3  0x00007f2baa6f2949 in apc_pthreadmutex_lock () from /usr/lib64/php5.3/lib/extensions/no-debug-non-zts-20090626/
#4  0x00007f2baa6eb84f in apc_cache_find_slot () from /usr/lib64/php5.3/lib/extensions/no-debug-non-zts-20090626/
#5  0x00007f2baa6ebab2 in apc_cache_find () from /usr/lib64/php5.3/lib/extensions/no-debug-non-zts-20090626/
#6  0x00007f2baa6f19ae in ?? () from /usr/lib64/php5.3/lib/extensions/no-debug-non-zts-20090626/
#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 "" and run "".

"request_terminate_timeout = 3" in php-fpm.conf

# cat /tmp/php-apcu/apcu.php
while (1 != 0) {
    apcu_store ("mykey", "123qwe");
    apcu_fetch ("mykey");

# cat /tmp/php-apcu/
while [ 0 != 1 ]; do
    SCRIPT_FILENAME=/tmp/php-apcu/apcu.php \
    cgi-fcgi -bind -connect
    sleep 3


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-18 20:59 UTC]
-Summary: APC/APCu + request_terminate_timeout cause deadlock +Summary: APCu: request_terminate_timeout cause deadlock
 [2021-06-22 12:19 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-06-22 12:19 UTC]
The bug tracker of APCu has been moved to Github[1].
If you stll experience this issue with the latest APCu
release (5.1.20), please report the issue there.

[1] <>
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Aug 17 02:05:45 2022 UTC