Memory leak on gRPC server using C++

134 views
Skip to first unread message

Srikanth

unread,
Jan 9, 2019, 8:51:33 PM1/9/19
to grpc.io
Hi,

I am using gRPC v1.17.2 for implementing CLI for my process. The gRPC server is in C++ and the client is in Golang. 

The protobuf definition looks like this

message GetResponseMsg {

  repeated GetResponse           response   = 1;    // response

}


message GetResponse {

  Spec         spec       = 1;

  Status       status     = 2;

  Stats        stats      = 3;

}


Each Response is probably around 500 Bytes in size all considered. The number of responses I am trying to retrieve runs to about 200000.


The server implementation looks like this


Status

Get(ServerContext *context,

                 const GetRequestMsg *req,

                 GetResponseMsg *rsp)

{

    uint32_t    i, nreqs = req->request_size();


    for (i = 0; i < nreqs; i++) {

        auto request = req->request(i);

        get(request, rsp->add_response());

    }


    return Status::OK;

}


Obviously with the size of each response and the number of responses I expect a lot of memory usage but thought the memory should be recovered after this command is run. But this memory is never recovered and I rapidly run out of memory and my process crashes. 


I enabled usage of Arena in the proto file but that didn't change anything. Is there anything I need to add to free up the memory used after the CLI command is run? 


I am a newbie to gRPC so am sorry if I have missed out on anything simple! Any help is appreciated.

Srikanth

unread,
Jan 14, 2019, 8:21:05 PM1/14/19
to grpc.io
Any help is appreciated. 

Are we supposed to call arena reset manually after the Get RPC is called?
Message has been deleted
Message has been deleted

yilun...@google.com

unread,
Mar 7, 2019, 1:08:27 PM3/7/19
to grpc.io
Would you please provide more information about how you free the service? I'm also not sure about how grpc gc works, maybe somebody from grpc team could give better answer.

PS: For manually free arena, you could use Reset

On Wednesday, January 9, 2019 at 5:51:33 PM UTC-8, Srikanth wrote:

Srikanth

unread,
Mar 22, 2019, 5:48:05 PM3/22/19
to grpc.io
Hi Yilun,

What do  you mean by free the service? Since I am trying to use this as CLI I am not freeing any service. If you mean that I have to free the "GetResponseMsg" that I get back as a response then can you please let me know how to do that?

Thanks,
Srikanth

Srikanth

unread,
Mar 23, 2019, 4:58:52 PM3/23/19
to grpc.io
Right now, I do not free any memory after parsing and printing the response received which runs in to thousands of entries.
Reply all
Reply to author
Forward
0 new messages