mediasoup: Possible memory leak

Hello,

I’m noticing increasing memory usage over time (~7GB in ~24h). I notice this with both glibc’s allocator and with jemalloc.
If I restart old servers, they can handle the same load with much less memory, so I don’t believe all 7GB are actually required.
If I disconnect all users from a server, most memory does not get returned.

I disconnected all users from a server that had been online for almost a day and then profiled the memory usage with jemalloc and found the allocations to look like this: image

To get another view, I started a server with heaptrack and after about an hour disconnected everyone and found a similar looking allocation breakdown: image

Is there a way I can get some more information on this issue that would be helpful (I saw there were some environment variables to start mediasoup with valgrind but I assume that doesn’t apply to Rust since it isn’t being started as a separate process? should I just run my whole application with valgrind?).

If it’s helpful information, we only use mediasoup for voip - no datachannels

We are specifically using mediasoup through Rust on commit d6373d5.

Thanks!

EDIT:

Upon further digging the issue is with WebRtcTransports created with a WebRtcServer.

In some cases we notice the client disconnect via our signaling layer (websocket) and then close the transport (I can see that the transport is closed because of the transport destructor logs). The TcpConnectionHandle does not get closed (I can see that the log in its destructor does not appear). Once I close the WebRtcServer, I see the TcpConnectionHandle close (again, through the log in its destructor)

About this issue

  • Original URL
  • State: closed
  • Created 2 months ago
  • Comments: 33 (32 by maintainers)

Commits related to this issue

Most upvoted comments

Ok I have a fix. Will write PR probably tomorrow.

Clear, thanks, so there is a clear bug then. I will get deep into this on next week. Can you please copy your exact previous comment into the issue description please?

You do have access, it is just hidden method in documentation because you’re not supposed to normally use it or rely on it, but might be helpful for debugging purposes.