|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-11-04 11:53 UTC] oliver at realtsp dot com
Description: ------------ sysV IPC semaphores are not cleaned up upon apc shutdown. initially I thought it might be this bug: http://bugs.php.net/bug.php?id=45423 patch to 5.2.6 realease here: http://cvs.php.net/viewvc.cgi/php- 6 but actually the behaviour before and after applying that patch to php5.2.6 is identical. apc_sem_destroy does appear to be called both with and without that patch. i added the following debug to apc_sem_destroy: void apc_sem_destroy(int semid) { /* we expect this call to fail often, so we do not check */ union semun arg; int semPid = semctl(semid, 1, GETVAL, 0); apc_wprint("semPid=%d, getpid()=%d, semid=%d", semPid, getpid(), semid); if (semPid == getpid()) { apc_wprint("apc_sem_destroy: semctl(%d, 0, IPC_RMID, arg)\n", semid); semctl(semid, 0, IPC_RMID, arg); } } code never gets inside that if statement. ie semPid == getpid() is never true. in fact semctl(semid, 1, GETVAL, 0) seems to return a value which is unrelated to any process id?? Is this the right call? the FreeBSD 7.0 man page for semctl says: GETVAL Return the value of semaphore number semnum. and when SETVAL is called during apc_sem_create(const char* pathname, int proj, int initval) it is set to initval which is passed as apc_lck_create(NULL, 0, 1, lock) where #define apc_lck_create(a,b,c,d) d=apc_sem_create(NULL,(b), ie initval=1 always? therefore GETVAL should always return 1...?? This is not what I am getting in my debug, but I am also not getting a valid pid and therefore the "pid" never matches and the semaphores are never removed. we are currently getting around the problem with some bash scripting on restart: /usr/local/etc/rc.d/fastcgi-php.sh stop # clean up the semaphores for id in `ipcs | grep www | awk '{print $2}'` do ipcrm -s $id done /usr/local/etc/rc.d/fastcgi-php.sh start Help anyone...am at the end of my C... Reproduce code: --------------- restart fastcgi server multiple times and monitor semaphore usage with root@torbay# ipcs Message Queues: T ID KEY MODE OWNER GROUP Shared Memory: T ID KEY MODE OWNER GROUP Semaphores: T ID KEY MODE OWNER GROUP s 5242880 0 --rwarwarwa www www s 5242881 0 --rwarwarwa www www s 5242882 0 --rwarwarwa www www s 1966083 0 --rwarwarwa www www s 1966084 0 --rwarwarwa www www s 1179653 0 --rwarwarwa www www Expected result: ---------------- semaphore are removed on shutdown and left lying around Actual result: -------------- semphores build up and eventually you get: [Mon Nov 3 23:04:58 2008] [apc-error] apc_sem_unlock: semop(3080192) failed: No space left on device due to the ultimately limited number available. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 04:00:01 2025 UTC |
thanks for your feedback. With apc.enable_cli="1" in my php.ini, i can reproduce the problem on cli as shown below: clearing any exsiting semaphores: root@torbay# ipcs -s Semaphores: T ID KEY MODE OWNER GROUP s 10485760 0 --rwarwarwa root wheel s 10485761 0 --rwarwarwa root wheel s 10485762 0 --rwarwarwa root wheel s 6750211 0 --rwarwarwa root wheel s 6750212 0 --rwarwarwa root wheel root@torbay# ipcs | awk "{ if (\$5 == \"root\") print \$2}" | xargs -n1 ipcrm -s proving there are none: root@torbay# ipcs -s Semaphores: T ID KEY MODE OWNER GROUP run php cli root@torbay# php -v PHP 5.2.6 (cli) (built: Nov 4 2008 16:18:13) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies 5 semaphores are left over root@torbay# ipcs -s Semaphores: T ID KEY MODE OWNER GROUP s 10551296 0 --rwarwarwa root wheel s 10551297 0 --rwarwarwa root wheel s 10551298 0 --rwarwarwa root wheel s 6815747 0 --rwarwarwa root wheel s 6815748 0 --rwarwarwa root wheel I am running php 5.2.6stable with ACP 3.0.19 + the patch you developed for http://pecl.php.net/bugs/bug.php?id=14949 and that patch is the reason there are 5 semaphores (without it there are 3). with regards to the line: semctl(semid, 1, GETVAL, 0); it is part of APC-3.0.19 not my code. I just printed that value to debug it, but was getting those "seemingly random values". Can you clarify what debug output you would like me to produce? ThanksI have added slightly different debug like this: void apc_sem_destroy(int semid) { /* we expect this call to fail often, so we do not check */ union semun arg; int semPid = semctl(semid, 1, GETVAL, 0); apc_wprint("apc_sem_destroy: checking if semaphore %d matches our pid: %d", semid, getpid()); if (semPid == getpid()) { apc_wprint("apc_sem_destroy: removing semaphore %d", semid); semctl(semid, 0, IPC_RMID, arg); } else { apc_wprint("apc_sem_destroy: semaphore %d is not ours it has semPid=%d", semid, semPid); } } and get this output, which is inline with previous results, ie the pid never matches. root@torbay# ipcs | awk "{ if (\$5 == \"root\") print \$2}" | xargs -n1 ipcrm -s root@torbay# php -v PHP 5.2.6 (cli) (built: Nov 4 2008 16:18:13) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies [Mon Nov 10 15:54:34 2008] [apc-warning] apc_sem_destroy: checking if semaphore 10944513 matches our pid: 76206 [Mon Nov 10 15:54:34 2008] [apc-warning] apc_sem_destroy: semaphore 10944513 is not ours it has semPid=10670 [Mon Nov 10 15:54:34 2008] [apc-warning] apc_sem_destroy: checking if semaphore 7208963 matches our pid: 76206 [Mon Nov 10 15:54:34 2008] [apc-warning] apc_sem_destroy: semaphore 7208963 is not ours it has semPid=10670 [Mon Nov 10 15:54:34 2008] [apc-warning] apc_sem_destroy: checking if semaphore 10944512 matches our pid: 76206 [Mon Nov 10 15:54:34 2008] [apc-warning] apc_sem_destroy: semaphore 10944512 is not ours it has semPid=10670 root@torbay# ipcs -s Semaphores: T ID KEY MODE OWNER GROUP s 10944512 0 --rwarwarwa root wheel s 10944513 0 --rwarwarwa root wheel s 10944514 0 --rwarwarwa root wheel s 7208963 0 --rwarwarwa root wheel s 7208964 0 --rwarwarwa root wheelright.... so the behaviour is different but not fixed for me yet... sorry for causing confusion by pasting all that Freebsd port patched code earlier...here is my new debug code which prints the retval of the semctl call as you suggested: void apc_sem_destroy(int semid) { /* we expect this call to fail often, so we do not check */ union semun arg; int retval; retval = semctl(semid, 0, IPC_RMID, arg); apc_wprint("semctl retval= %d", retval); } and this is the test run with that debug: root@torbay# ipcs -s Semaphores: T ID KEY MODE OWNER GROUP root@torbay# php -v PHP 5.2.6 (cli) (built: Nov 4 2008 16:18:13) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies [Mon Nov 10 19:10:36 2008] [apc-warning] semctl retval= 0 [Mon Nov 10 19:10:36 2008] [apc-warning] semctl retval= 0 [Mon Nov 10 19:10:36 2008] [apc-warning] semctl retval= 0 root@torbay# ipcs -s Semaphores: T ID KEY MODE OWNER GROUP s 11272194 0 --rwarwarwa root wheel s 7536644 0 --rwarwarwa root wheel so just 2 semaphore rather than 5 (which seems more logical...one blocking and one non-blocking)...but they still hand around... next suggestion?more info... tried to reduce fastcgi server to one process but min i could get is 3, 1 parent + 2 children..so sticking to cli and running: php -r 'sleep(10);' five semaphores are still used and then 3 are removed successfully (hence the 0 retvals in previous debug) but 2 remain: while php-cli is running: oliver@torbay$ ipcs -s Semaphores: T ID KEY MODE OWNER GROUP s 12451840 0 --rwarwarwa root wheel s 12451841 0 --rwarwarwa root wheel s 11927554 0 --rwarwarwa root wheel s 8454147 0 --rwarwarwa root wheel s 8192004 0 --rwarwarwa root wheel after it finishes: oliver@torbay$ ipcs -s Semaphores: T ID KEY MODE OWNER GROUP s 11927554 0 --rwarwarwa root wheel s 8192004 0 --rwarwarwa root wheel so that points the finger to the calling code I guess? for (i = 0; i < sma_numseg; i++) { apc_lck_destroy(((header_t*)sma_shmaddrs[i])-