]> git.kaiwu.me - nginx.git/commit
Upstream: reinit upstream after reading bad response.
authorRoman Arutyunyan <arut@nginx.com>
Wed, 28 Jan 2026 16:38:38 +0000 (20:38 +0400)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 4 Feb 2026 15:09:20 +0000 (19:09 +0400)
commitd7a249470b78a155c7548aea5f4eb959dae9fd03
tree278f160f6bf7b2d52a133e6e608933b363db272a
parenta59f5f099a89dc8eaebd48077292313f9f7e33e3
Upstream: reinit upstream after reading bad response.

Previously, when connecting to a backend, if the read event handler was
called before the write event handler, and the received response triggered
a next upstream condition, then ngx_http_upstream_reinit() was not called
to clean up the old upstream context.  This had multiple implications.

For all proxy modules, since the last upstream response was not cleaned up,
it was mixed with the next upstream response.  This could result in ignoring
the second response status code, duplicate response headers or reporting
old upstream header errors.

With ngx_http_grpc_module and ngx_http_proxy_v2_module, ctx->connection
was left dangling since the object it referenced was allocated from the
last upstream connection pool, which was deleted when freeing last upstream.
This lead to use-after-free when trying to reuse this object for the next
upstream.
src/http/ngx_http_upstream.c
src/http/ngx_http_upstream.h