No subject

Sangmin Lee leesm815 at gmail.com
Fri Apr 5 02:12:27 UTC 2024


Hello,

I think I found the main casue of memory leak issue when using gRPC stream
so I made a patch for it.
Please find the test scenario and details here -- This is what I wrote.:
https://trac.nginx.org/nginx/ticket/2614

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.
like below picture.

[image: Screenshot from 2024-04-02 11-49-29.png]

After I patched one part, it seems okay now I have tested it for 1 week
with out workload.

[image: Screenshot from 2024-04-04 15-47-14.png]

But because I am not familiar with the Mercurial so I couldn't find a way
to create PR like on github.

I guess this mailing list is for this patch. So I would like to further
discuss here.
>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;
so this ngx_chain_t instance should be dealt with differently unlike other
ngx_chain_t instances.
But I am quite new to nginx codes so my view could be wrong.
Anyhow, please consider this


diff --git a/src/http/modules/ngx_http_grpc_module.c
b/src/http/modules/ngx_http_grpc_module.c
index dfe49c586..1db67bd0a 100644
--- a/src/http/modules/ngx_http_grpc_module.c
+++ b/src/http/modules/ngx_http_grpc_module.c
@@ -1462,6 +1462,12 @@ ngx_http_grpc_body_output_filter(void *data,
ngx_chain_t *in)
         in = in->next;
     }

+       ngx_chain_t *nl;
+       for (ngx_chain_t *dl = ctx->in; dl != in; dl = nl ) {
+               nl = dl->next;
+               ngx_free_chain(r->pool, dl);
+       }
+
     ctx->in = in;

     if (last) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20240405/14f14f19/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2024-04-02 11-49-29.png
Type: image/png
Size: 371470 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20240405/14f14f19/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2024-04-04 15-47-14.png
Type: image/png
Size: 65011 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20240405/14f14f19/attachment-0003.png>


More information about the nginx-devel mailing list