php.net |  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
Votes:10
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:
MUST BE VALID
Solve the problem:
17 - 2 = ?
Subscribe to this entry?

 
 [2015-02-13 00:34 UTC] fadimko at gmail dot com
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
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] <https://github.com/krakjoe/apcu/issues>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 15:01:29 2024 UTC