[php-src] Issue #12914: pcntl cause processes to not exit cleanly

From: Date: Sat, 09 Dec 2023 16:08:24 +0000
Subject: [php-src] Issue #12914: pcntl cause processes to not exit cleanly
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246022@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12914 Author: vishwarajanand ### Description The following code: ```php <?php // filename is test.php $pid = pcntl_fork(); if ($pid == -1) { die('could not fork'); } elseif ($pid) { // parent process pcntl_waitpid($pid, $status); // protect against Zombie children } else { // child process // do some work here exit(0); // ensure that the child process exits } ``` Resulted in a process hang, (forever wait on pcntl_waitpid) when it should return cleanly. php test.php // hangs forever Following are some logs for helpful debugging: 1. test.php creates a process, so we fetch their pid like this: ``` ➜ test git:(main) ✗ ps -aux | grep test.php vishwar+ 3971611 0.2 0.0 317716 30804 pts/0 Sl+ 15:39 0:00 php test.php vishwar+ 3971625 0.0 0.0 294876 13204 pts/0 S+ 15:39 0:00 php test.php vishwar+ 3971767 0.0 0.0 6488 1920 pts/1 S+ 15:39 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox test.php ``` 2. We tested to find out where the process is awaiting. ``` sudo strace -f -p 3971622 -o output.txt 3971622 futex(0x7fdd9a28c740, FUTEX_WAIT_PRIVATE, 0, NULL <unfinished ...> 3971624 restart_syscall(<... resuming interrupted read ...> <unfinished ...> 3971623 futex(0x7fdd9a28cd40, FUTEX_WAIT_PRIVATE, 0, NULL <unfinished ...> 3971611 wait4(3971625, <unfinished ...> 3971624 <... restart_syscall resumed>) = -1 ETIMEDOUT (Connection timed out) 3971624 futex(0x7fdd9a28d340, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, {tv_sec=1702136412, tv_nsec=791623840}, FUTEX_BITSET_MATCH_ANY ``` 3. Same for the other process. ``` sudo strace -f -p 3971625 -o output.txt 3971625 futex(0x7fdd9a28c140, FUTEX_WAIT_PRIVATE, 0, NULL ``` Logs suggest that both the process is awaiting onfutex , but it never gets woken up. ### PHP Version PHP 8.2.10 ### Operating System Debian Linux

« previous php.bugs (#246022) next »