Skip to content

Fix GH-24229: fcgi_close() passes shutdown() a literal 1 - #24230

Closed
mpyw wants to merge 1 commit into
php:PHP-8.4from
mpyw:fix-fastcgi-shutdown-wr
Closed

mpyw wants to merge 1 commit into
php:PHP-8.4from
mpyw:fix-fastcgi-shutdown-wr

Conversation

@mpyw

@mpyw mpyw commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes GH-24229.

The quoted description below, and the checks it describes, were done with an LLM (Claude). I reviewed them.

fcgi_close() half-closed the connection with shutdown(req->fd, 1), meaning SHUT_WR, as the comment after it says. Every platform PHP supports uses 1 for SHUT_WR, but POSIX does not fix the value. WASI uses 2, and 1 is SHUT_RD there.

With the read side shut, the drain loop ended at once. close() could then run with the web server's last FCGI_STDIN unread, and Linux reset the connection. That discarded the response before the web server read it.

This uses SHUT_WR, which <sys/socket.h> already provides there. The _WIN32 branch is left as is: 1 is SD_SEND, which is right on Windows.

There is no test: on the supported platforms, SHUT_WR is 1, so nothing changes. I checked that in a build of this branch, configured with --disable-all --enable-cli --enable-cgi --enable-fpm on Debian trixie. sapi/cgi/tests and sapi/fpm/tests give the same results with and without this change: 132 passed, 26 skipped, and the same 2 failures, which come from running them as root in a container.

The fix itself was checked with php-cgi built for wasm32-wasip1, in FastCGI mode on wazero. On Linux, 10 of 600 requests failed before it, and none after.

This targets PHP-8.4 as the lowest branch with bug fixes. I am happy to retarget it to master if you see this as a portability change rather than a bug fix.

fcgi_close() half-closed the connection with shutdown(fd, 1), meaning
SHUT_WR. Every platform PHP supports uses 1 for it, but POSIX does not fix
the value, and WASI uses 2. There the reading side was shut instead. The
drain loop then ended at once, and close() could reset the connection with
the web server's last FCGI_STDIN unread, which lost the response.
@mpyw
mpyw requested a review from bukka as a code owner October 9, 2026 20:39

@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.

You're correct, and SHUT_WR==1 on Linux, thanks

@ndossche ndossche linked an issue Oct 9, 2026 that may be closed by this pull request
LamentXU123 added a commit that referenced this pull request Oct 10, 2026
* PHP-8.6:
  Fix GH-24229: Use SHUT_WR when closing FastCGI connections (#24230)
@LamentXU123

Copy link
Copy Markdown
Member

Thank you!

bukka pushed a commit to bukka/php-src that referenced this pull request Oct 10, 2026
* PHP-8.4:
  Fix phpGH-24229: Use SHUT_WR when closing FastCGI connections (php#24230)
bukka pushed a commit to bukka/php-src that referenced this pull request Oct 10, 2026
* PHP-8.5:
  Fix phpGH-24229: Use SHUT_WR when closing FastCGI connections (php#24230)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fcgi_close() passes shutdown() a literal 1, which is SHUT_RD in WASI

3 participants