Built-in server leaks a file descriptor on every HEAD request for a static file
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 88/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- cli, networking
Direzione di ricerca
Inizia in sapi/cli/php_cli_server.c, in php_cli_server_begin_send_static(), quindi esegui il php -S fornito e la riproduzione con curl HEAD ripetuti. Il lavoro è completato quando richieste HEAD ripetute a un file statico non aumentano più il numero di descrittori di file aperti, mentre le normali risposte statiche continuano a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Since PHP 8.2 (#8215), php_cli_server_begin_send_static() in sapi/cli/php_cli_server.c opens the static file but only stores the descriptor in client->file_fd for non-HEAD requests:
fd = open(client->request.path_translated, O_RDONLY);
...
if (client->request.request_method != PHP_HTTP_HEAD) {
client->file_fd = fd;
}
For HEAD, fd is never stored and never closed. Each HEAD request to a static file leaks one descriptor; once RLIMIT_NOFILE is reached every request fails with 404 ... Too many open files. A monitoring probe doing HEAD / every 40 s takes down php -S in ~11 hours.
Affected: PHP-8.2, PHP-8.3, PHP-8.4, PHP-8.5, master. PHP 8.1 is not affected (no HEAD special-casing).
Reproduction:
mkdir t && echo hi > t/index.html
php -S 127.0.0.1:8080 -t t &
for i in $(seq 100); do curl -sI http://127.0.0.1:8080/ >/dev/null; done
ls -l /proc/$!/fd | grep -c index.html # 100
Suggested fix — close the descriptor when it is not handed to the content sender (Content-Length uses client->request.sb.st_size from the earlier stat, so the fd is not needed for HEAD at all):
if (client->request.request_method != PHP_HTTP_HEAD) {
client->file_fd = fd;
} else {
close(fd);
}
PHP Version
PHP 8.2 – 8.5, master
Operating System
Linux (any)
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.2k
- Merge medio
- 2g 14h
- PR unite (30g)
- 112
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di php/php-src
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Bug Status: Needs Triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Flaky hrtime.phpt test ApertaBug Category: Tests Status: Verified
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Bug SAPI: fpm Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
libsdl-org/SDL#16360 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zephyrproject-rtos/zephyr#119726 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
api7/lua-resty-saml#63 ·
-
[Bounty proposal] fix(web): memory insights count an evening memory on the next day ($25 proposed) Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
BasedHardware/omi#15320 ·