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: 2016-11-18 20:59 UTC
Votes:9
Avg. Score:4.7 ± 0.7
Reproduced:7 of 8 (87.5%)
Same Version:4 (57.1%)
Same OS:6 (85.7%)
From: fadimko at gmail dot com Assigned:
Status: Open Package: APC (PECL)
PHP Version: 5.5.21 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fadimko at gmail dot com
New email:
PHP Version: OS:

 

 [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
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC