<div dir="ltr"><div>I am sending this mail again because I did a mistake while I was writing a mail. I didn't know, in gmail, "Ctrl - Enter" would send a mail immediately even without a title! </div><div>I am sorry for that, so I am sending again.</div><div><br></div>Hello, <div><br></div><div>I think I found the main cause of the 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" target="_blank">https://trac.nginx.org/nginx/ticket/2614</a><br><br></div><div>After I changed the memory pool totally on nginx and tested 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 the picture below. </div><div><br><img src="cid:ii_lum0uky20" alt="Screenshot from 2024-04-02 11-49-29.png" width="444" height="218" class="gmail-CToWUd gmail-a6T" tabindex="0" style="cursor: pointer; outline: 0px;"><br></div><div>( I am not sure whether this picture will be sent properly )<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" class="gmail-CToWUd gmail-a6T" tabindex="0" style="cursor: pointer; outline: 0px;"><div>( I am not sure whether this picture will be sent properly )</div><div><br><div>But because I am not familiar with Mercurial, I couldn't find a way to create PR like on github. I guess this mailing list is for this patch.</div><div><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 might be wrong.</div><div>Anyhow, please go over this patch and I would like to further talk here.</div><div><div><br></div><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) {<div class="gmail-yj6qo"></div><div class="gmail-adL"><br></div></div></div></div><div class="gmail-adL">--------------------------------------------------------------------------------------------------------------------------------------------<br></div><div class="gmail-adL"><br></div><div class="gmail-adL">Best regards,<br></div><div class="gmail-adL">Sangmin</div></div>