php / php/php-src

PHP 8.2 FPM Leaks processes on pcntl_fork

Open
#12,155 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: pcntl Feature Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

OS: xenial
PHP tested: 8.2.7, 8.2.10

The following drupal 10 index.php:

<?php

/**
 * @file
 * The PHP page that serves all page requests on a Drupal installation.
 *
 * All Drupal code is released under the GNU General Public License.
 * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
 */

use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

$kernel = new DrupalKernel('prod', $autoloader);

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$pid = pcntl_fork();
    if ( $pid !== 0  ) {
        // we are the parent process
        return;
    }
    sleep(10);

$kernel->terminate($request, $response);

After doing ~5 requests to the site, results in the following sub-processes to the FPM master:

root     15873  0.0  0.8 464188 17200 ?        Ss   13:08   0:00 php-fpm: master process (/var/www/site-fpm/drush12test.prod/php-fpm-8.2.conf)
drush12+ 16518  0.7  1.4 466300 29860 ?        S    13:11   0:00  \_ php-fpm: pool drush12test
drush12+ 16557  0.0  0.6 466300 13068 ?        S    13:11   0:00      \_ php-fpm: pool drush12test
drush12+ 16559  0.0  0.6 466300 12640 ?        S    13:11   0:00      \_ php-fpm: pool drush12test
drush12+ 16561  0.0  0.6 466300 12640 ?        S    13:11   0:00      \_ php-fpm: pool drush12test
drush12+ 16563  0.0  0.6 466300 12640 ?        S    13:11   0:00      \_ php-fpm: pool drush12test

But then after a few seconds, when it should clean them up, they will instead detach and linger around:

root     15873  0.0  0.8 464188 17188 ?        Ss   13:08   0:00 php-fpm: master process (/var/www/site-fpm/drush12test.prod/php-fpm-8.2.conf)
drush12+ 16557  0.0  1.1 464252 23364 ?        S    13:11   0:00 php-fpm: pool drush12test
drush12+ 16559  0.0  1.1 464252 23028 ?        S    13:11   0:00 php-fpm: pool drush12test
drush12+ 16561  0.0  1.1 464252 23028 ?        S    13:11   0:00 php-fpm: pool drush12test
drush12+ 16563  0.0  1.1 466300 23432 ?        S    13:11   0:00 php-fpm: pool drush12test

The same doesn't happen with PHP 7.4. In that case the processes get cleaned up properly.

PHP Version

PHP 8.2.10

Operating System

Ubuntu 16.04

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Drupal 10 index.php reproducer, especially the pcntl_fork() call and the PHP-FPM process behavior. Reproduce it with PHP 8.2.10 on Ubuntu 16.04 and compare with PHP 7.4. Done means the forked processes are cleaned up after the sleep instead of detaching and lingering under the FPM master.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.