[php-src] Issue #24506: `stream_select()` leaks a stream-error operation level on its FD_SETSIZE failure path
| From: | azjezz | Date: | Wed, 21 Oct 2026 20:27:58 +0000 |
| Subject: | [php-src] Issue #24506: `stream_select()` leaks a stream-error operation level on its FD_SETSIZE failure path | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-253064@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/24506
Author: azjezz
### Description
Each
stream_select() call that hits the PHP_SAFE_MAX_FD check (any fd
>= FD_SETSIZE, 1024 on macOS and Linux) emits its "You MUST
recompile PHP with a larger value of FD_SETSIZE" warning and returns false. It
also leaves one operation level open.
After 1,000 such calls, **every later stream operation in the process** (fread,
fwrite, ..etc) emits:
```
Warning: fread(): Stream error operation depth exceeded (1000), possible infinite recursion
```
The operation itself still succeeds. The warnings never stop until the process exits.
Example:
```php
$keep = [];
while (true) { // open sockets until one has fd >= 1024
$p = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
$keep[] = $p;
if (count($keep) * 2 > 1100) {
break;
}
}
[$hi] = end($keep);
[$a, $b] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
$calls = (int) ($argv[1] ?? 1001);
for ($i = 0; $i < $calls; $i++) {
$r = [$hi]; $w = $e = null;
@stream_select($r, $w, $e, 0);
}
fwrite($b, 'x');
$last = null;
set_error_handler(function ($no, $str) use (&$last) {
$last = $str;
return true;
});
$data = fread($a, 1);
restore_error_handler();
printf("after %d over-limit stream_select() calls: fread()=%s warning=%s\n", $calls,
var_export($data, true), $last ?? 'none');
```
```sh
ulimit -n 4096
php reproduce.php 2000 # 8.6.0RC3: warning=fread(): Stream error operation depth exceeded (1000)...
php reproduce.php 999 # no warning
```
On 8.5.4 the same script prints warning=none.
### PHP Version
```plain
PHP 8.5.4 (cli) (built: Mar 31 2026 17:40:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.4, Copyright (c) Zend Technologies
with Zend OPcache v8.5.4, Copyright (c), by Zend Technologies
```
### Operating System
MacOS