<div dir="ltr">Hello, <div><br></div><div>I think I found the main casue of memory leak issue when using gRPC stream so I made a patch for it. </div><div>Please find the test scenario and details here -- This is what I wrote.:</div><div><a href="https://trac.nginx.org/nginx/ticket/2614">https://trac.nginx.org/nginx/ticket/2614</a><br><br></div><div>After I have changed memory pool totally on nginx and test our workload -- long-lived gRPC streams with many connections -- using Valgrind and massif, I was able to find what brought up the memory leak issue.</div><div>like below picture.</div><div><br><img src="cid:ii_lum0uky20" alt="Screenshot from 2024-04-02 11-49-29.png" width="444" height="218"><br></div><div><br></div><div>After I patched one part, it seems okay now I have tested it for 1 week with out workload.</div><div><br></div><img src="cid:ii_lum0unex1" alt="Screenshot from 2024-04-04 15-47-14.png" width="444" height="356"><div><br><div>But because I am not familiar with the Mercurial so I couldn't find a way to create PR like on github.</div><div><br>I guess this mailing list is for this patch. So I would like to further discuss here.<br><div>From my point of view, it is more like a workaround and I think the way of using ngx_chain_add_copy() or itself needs to be changed because it allocates a ngx_chain_t structure using ngx_alloc_chain_link() but inside of that, it just copies pointer, like cl->buf = in->buf;</div>so this ngx_chain_t instance should be dealt with differently unlike other ngx_chain_t instances.</div><div>But I am quite new to nginx codes so my view could be wrong.</div><div>Anyhow, please consider this <br><div><br></div><div><br></div><div>diff --git a/src/http/modules/ngx_http_grpc_module.c b/src/http/modules/ngx_http_grpc_module.c<br>index dfe49c586..1db67bd0a 100644<br>--- a/src/http/modules/ngx_http_grpc_module.c<br>+++ b/src/http/modules/ngx_http_grpc_module.c<br>@@ -1462,6 +1462,12 @@ ngx_http_grpc_body_output_filter(void *data, ngx_chain_t *in)<br>         in = in->next;<br>     }<br> <br>+       ngx_chain_t *nl;<br>+       for (ngx_chain_t *dl = ctx->in; dl != in; dl = nl ) {<br>+               nl = dl->next;<br>+               ngx_free_chain(r->pool, dl);<br>+       }<br>+<br>     ctx->in = in;<br> <br>     if (last) {<br></div></div></div></div>