[php-src] PR #26049: Fix GH-18275: Ignore FastCGI writes/flushes after fcgi_end()
| From: | hohphu8 | Date: | Thu, 03 Dec 2026 09:58:32 +0000 |
| Subject: | [php-src] PR #26049: Fix GH-18275: Ignore FastCGI writes/flushes after fcgi_end() | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41388@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/26049
Author: hohphu8
Fixes GH-18275.
When a FastCGI connection uses
FCGI_KEEP_CONN (such as nginx with
fastcgi_keep_conn on), fastcgi_finish_request() calls
fcgi_end() and fcgi_close(request, 0, 0), sending
FCGI_END_REQUEST and setting req->ended = 1 while keeping
req->fd open for subsequent requests. Because fcgi_write() and
fcgi_flush() did not check req->ended, any post-finish output or
FCGI_STDERR logging that causes a flush (via implicit_flush, explicit
flush(), or writes exceeding the 8 KiB output buffer) wrote FastCGI records onto the
live keepalive socket after FCGI_END_REQUEST, corrupting the next request's
response headers and status on that connection. Additionally, fcgi_is_closed() only
checked req->fd < 0, so repeated fastcgi_finish_request() calls on
keepalive connections returned true instead of false.
This change updates fcgi_is_closed() to also consider req->ended, and
makes fcgi_write() and fcgi_flush() return success (len and
1 respectively) without buffering or writing any data once req->ended
is set, so post-finish output is silently discarded without triggering
php_handle_aborted_connection() on background shutdown work. A regression test covering
both small post-finish writes with implicit flush and large writes / FCGI_STDERR /
explicit flush() over a reused keepalive connection is included.