Skip to content

Fix GH-23764: Built-in server leaks fd on HEAD request for static file - #23765

Open
jakubskopal wants to merge 1 commit into
php:PHP-8.4from
jakubskopal:fix-gh-23764
Open

jakubskopal wants to merge 1 commit into
php:PHP-8.4from
jakubskopal:fix-gh-23764

Conversation

@jakubskopal

@jakubskopal jakubskopal commented Sep 19, 2026

Copy link
Copy Markdown

Fixes GH-23764.

php_cli_server_begin_send_static() opens the file, but for HEAD requests never stores the descriptor in client->file_fd, so nothing closes it. Close it right away; Content-Length comes from the stat and the body is never sent, so the descriptor is not needed.

Verified with a --disable-all build: after 100 curl -I requests, /proc/<pid>/fd holds 0 references to the served file (previously 100); HEAD and GET responses unchanged.

Bug exists since 8.2 (#8215); targeting PHP-8.4 as the lowest branch still receiving bug fixes.

@ndossche ndossche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps an even better fix is to avoid the open call and only rely on the stat call from earlier. What do you think?

@jakubskopal
jakubskopal force-pushed the fix-gh-23764 branch 2 times, most recently from a31ded7 to 91c79b1 Compare September 21, 2026 08:43
@jakubskopal

jakubskopal commented Sep 21, 2026

Copy link
Copy Markdown
Author

Have a look. I've amended the commit. HEAD should theoretically return the same status as GET, so one needs to check permissions to be able to do that (open not only opens, but also checks readability). I'm not sure one saved call (open+close vs. access) is worth the 10 lines added. Let me know which one you prefer. I personally would prefer the former.

@ndossche

Copy link
Copy Markdown
Member

Yeah okay, you're right. Please go back to the original solution and I'll approve. Thanks for checking.

@jakubskopal
jakubskopal force-pushed the fix-gh-23764 branch 2 times, most recently from 9da759a to ca40258 Compare September 22, 2026 05:28
…file

php_cli_server_begin_send_static() opens the file, but for HEAD requests
never stores the descriptor in client->file_fd, so nothing closes it.
Close it right away; Content-Length comes from the stat and the body is
never sent, so the descriptor is not needed.
@jakubskopal

Copy link
Copy Markdown
Author

okay, done :-) i've put it in the comment so that it's a bit clearer, let me know if I should take it out, i see there are not many comments in PHP source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants