unispeech / unimrcp

Open source cross-platform implementation of MRCP protocol
http://www.unimrcp.org
Apache License 2.0
374 stars 165 forks source link

maybe memory leak #294

Closed lizhenghn123 closed 3 years ago

lizhenghn123 commented 3 years ago

https://github.com/unispeech/unimrcp/blob/7c8703d6fe4d9816bf635b2848e3657606729fe3/plugins/demo-synth/src/demo_synth_engine.c#L394, in this line, i see mrcp_response_create, which malloc some memory, then init and send it, but it seems do not free the memory.

i see the function : mrcp_message_create, but don't see : mrcp_message_destroy. so maybe it memory leak ?

am i wrong?

achaloyan commented 3 years ago

The memory is allocated from the session pool and is released when the session is closed (the session pool is cleared). So, it is not a memory leak.

lizhenghn123 commented 3 years ago

Yes , when the session close, the memory pool is released. But if the session don't close never, example: long connection, how to do release memory manually? Otherwise the memory may be alloc util all is used.

How to reproduce? The CallCenter has a long connection with unimrcp, which the connection once created, it never close (unless reboot or network down). In the case, the connection may be process many many the same requests one and one after, and how to release memory ?

If i don't describe clearly, may be the logs usfull ?

achaloyan commented 3 years ago

The parameter max-shared-use-count prevents unconditional memory growth in the scenarios that you described. The default value of this parameter is 100, which means a single connection can be used for up to 100 sessions. Afterwards, the client will be forced to use a new connection. As a result, the existing connection will be closed and the associated memory released. There is also inactivity-timeout that is set to 600 seconds by default.

lizhenghn123 commented 3 years ago

Thanks for your reply!

Yes the config " inactivity-timeout" is work fine, but not in this case.

Now it's a long tcp connection which may be keep some days, and the server(unimrcp) can not close the connection.

If the server close the existing connection by itself, maybe one new request(for example, SPEAK) is transmissing on this connection by client.

So can you give more advice? Thanks.

achaloyan commented 3 years ago

Are you talking about an MRCP session or a TCP/IP connection used to carry over MRCP messages. It is very uncommon to have a long-lived MRCP session. Thought, it is possible to use a single connection for multiple MRCP sessions. The server may introduce a limit in the number of sessions using the same connection (see max-shared-use-count), wait for existing sessions to complete normally and then close the no longer used connection.