[nginx] gRPC: reinitialization of in, out, and busy chains.

Maxim Dounin mdounin at mdounin.ru
Fri Mar 6 04:10:24 UTC 2026


details:   http://freenginx.org/hg/nginx/rev/3de452bb4b91
branches:  
changeset: 9470:3de452bb4b91
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Fri Mar 06 07:09:06 2026 +0300
description:
gRPC: reinitialization of in, out, and busy chains.

If an error happens with data buffered in ctx->in (or control frames
queued in ctx->out), keeping these while switching to the next upstream
server will result in incorrect data sent to the new connection, likely
causing a failure.

Similarly, if there are buffers in ctx->busy, switching to the next
upstream server will reinitialize ngx_chain_writer() context, u->writer,
and these buffers will be forgotten.  Still, since they are in ctx->busy
and not marked as fully sent, ngx_chain_update_chains() won't look any
further, thus breaking buffers reuse and causing excessive memory usage
on long-running requests.

The fix is to clear ctx->in, ctx->out, and ctx->busy chains on request
reinitialization.

Prodded by David Carlier,
https://freenginx.org/pipermail/nginx-devel/2026-February/000934.html

diffstat:

 src/http/modules/ngx_http_grpc_module.c |  3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diffs (13 lines):

diff --git a/src/http/modules/ngx_http_grpc_module.c b/src/http/modules/ngx_http_grpc_module.c
--- a/src/http/modules/ngx_http_grpc_module.c
+++ b/src/http/modules/ngx_http_grpc_module.c
@@ -1217,6 +1217,9 @@ ngx_http_grpc_reinit_request(ngx_http_re
     ctx->rst = 0;
     ctx->goaway = 0;
     ctx->connection = NULL;
+    ctx->in = NULL;
+    ctx->out = NULL;
+    ctx->busy = NULL;
     ctx->pings = 0;
     ctx->settings = 0;
     ctx->headers = 0;


More information about the nginx-devel mailing list