[php-src] Issue #11765: FPM idle or req timeout causes no child available if write is delayed

From: Date: Sat, 22 Jul 2023 14:25:07 +0000
Subject: [php-src] Issue #11765: FPM idle or req timeout causes no child available if write is delayed
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245011@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11765
Author: bukka

### Description

This problem can happen in ondemand mode if the connection is established but there is a significant
write delay and pm.process_idle_timeout is set even to shorter value. In such case
process idle can remove all children. But probably because the connection is established, it is past
creating new child so the request fails.

The following tests results in such issue:

```php
--TEST--
FPM: Process manager config pm.process_idle_timeout with keep alive set
--SKIPIF--
<?php
include "skipif.inc";
if (!getenv("FPM_RUN_RESOURCE_HEAVY_TESTS")) die("skip resource heavy test");
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
?>
--FILE--
<?php

require_once "tester.inc";

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
log_level = debug
[unconfined]
listen = {{ADDR}}
pm = ondemand
pm.max_children = 3
pm.min_spare_servers = 1
pm.process_idle_timeout = 1
pm.status_path = /status
;request_terminate_timeout = 2
EOT;

$code = <<<EOT
<?php
usleep(300000);
EOT;

$tester = new FPM\Tester($cfg, $code, clientTransport: 'stream');
$tester->start();
$tester->expectLogStartNotices();
//$tester->multiRequest(2, connKeepAlive: true);
$tester->multiRequest(2, connKeepAlive: true, writeDelay: 3000, readTimeout: 5000);
$tester->status([
    'total processes' => 2,
]);
// wait for process idle timeout
sleep(2);
$tester->status([
    'total processes' => 2,
]);
$tester->terminate();
$tester->expectLogTerminatingNotices();
$tester->close();

?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>
```

Resulted in this output:
```
PHP Notice:  fwrite(): Send of 611 bytes failed with errno=104 Connection reset by peer
```

But I expected this output instead:
```
no error
```


### PHP Version

PHP 8

### Operating System

Linux


Thread (1 message)

  • bukka
« previous php.bugs (#245011) next »