Built-in server leaks a file descriptor on every HEAD request for a static file
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- cli, networking
Hướng nghiên cứu
Bắt đầu trong sapi/cli/php_cli_server.c tại php_cli_server_begin_send_static(), sau đó chạy php -S được cung cấp và quy trình tái hiện bằng curl HEAD lặp lại. Hoàn tất khi các yêu cầu HEAD lặp lại đến một tệp tĩnh không còn làm tăng số lượng trình mô tả tệp đang mở, đồng thời các phản hồi tĩnh thông thường vẫn tiếp tục hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.2k
- Merge trung bình
- 2 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 112
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của php/php-src
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Bug Status: Needs Triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Flaky hrtime.phpt test Đang mởBug Category: Tests Status: Verified
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Bug SAPI: fpm Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
level/task module/gcp type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
-
Build failure with newer clang Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
hapostgres/pg_auto_failover#1190 ·
-
docs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
P3 sonic-vpp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
sonic-net/sonic-buildimage#29662 ·