]> 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 17:22:23 +0000 (21:22 +0400)
commit6df8054cb21b4e5e857b4489e623a79575c2ab8e
tree5852e1f53159c0354c85093c03f09606d46b2ad3
parent784fa05025cb8cd0c770f99bc79d2794b9f85b6e
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