You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I mean I experience the same issue. I've checked all the app code several times and the only potential leak must be in some libraries (unless I lost my sanity along the way).
It's not like I'm leaking huge number of memory, I have just 1:1 calls and on average I leak ~30KB per session which would be couple of packets at most but with thousands of sessions it adds up and drains all the memory after like 1,5 weeks and I need to restart the machine.
From the memory profiles I haven't seen anything big besides the nack module (I have a copied version from the repo and am using it in some other module but the code is the same) so seeing that you have a similar problem gave me a little more hope.
By hold I mean keep a reference or never close it.
Not closing it probably woulld show up in the number of goroutines and in my case those are not ever-increasing.
I am also wondering if that has something to do maybe with the ion code? I have part of the codebase that has code taken from livekit (mainly handling of the peer connection) but as far as I know the livekit also has a quite big chunk from ion sfu.
I am also wondering if that has something to do maybe with the ion code? I have part of the codebase that has code taken from livekit (mainly handling of the peer connection) but as far as I know the livekit also has a quite big chunk from ion sfu.
I'm also using ion, if sfu.PeerLocal never closed, the room never get closed, it causes leaks exactly like this, and it never increase the grouting number, you should go through your code to see if you missed to handle some ICE state change event.
Did you guys see that Ion is getting a reboot / remake, if you have any ideas for stuff you want to have or want to contribute please share your ideas, we're working on the draft right now pion/ion#1
Did you guys see that Ion is getting a reboot / remake, if you have any ideas for stuff you want to have or want to contribute please share your ideas, we're working on the draft right now pion/ion#1
Oh yea!
For one thing I'm now working on related to ion: adding rtmp ingress support.
Would be great to get RTMP support into Ion. I would love to also make it all Pure Go. If we ingest AAC would be really cool if we could get a Pure Go decoder. Would be fun to work on.
Would be great to get RTMP support into Ion. I would love to also make it all Pure Go. If we ingest AAC would be really cool if we could get a Pure Go decoder. Would be fun to work on.
I can make a simple application to try to debug that, maybe we have a memory leak. I can try something this weekend!
I've been doing a lot of semi-synthetic testing, and I couldn't reproduce it. It only happened on production so in fact it may have something to do with handling ICE states (with testing it is hard to reproduce what users are actually experiencing). What is more strange is that the leak is constant and is not that high per session, I would expect if we leak nack packets it would be in MBs instead of couple of KBs (but I may be wrong, maybe it happens sporadically and with prod traffic it is not noticable?).
Actually @tubzby might have been right about not properly closing something. I doubt it have anything to do with the interceptor itself. I've just checked the garbage collection of my session entity and for very little amount of sessions it doesn't get cleaned up.
The package indeed is not leaking. Found a bug on my side with a leaking goroutine (custom congestion control) that was keeping a reference to the peer connection, effectively keeping the interceptor.
@joeturki Sorry to bring this up, I have observed from go tool pprof that sync.Pool in this crate consumed 1832MB of memory, with only 5 tracks uploading, from the code it should be only: 5 * 1024(max packet per track) * 1460(MTU) ~ 7.5MB.
If memory consumption is that large, I'm leaking tracks/pcs, am I correct?
@tubzbysync.Pool on its own is doing garbage collection (or rather let's garbage collection claim some objects) so the memory leaked is in the objects that something else is holding. Are you sure you are not leaking some goroutines? For me even small amount (like 100) greatly contributed to the overall memory usage.
@tubzby I just merged the branch in 1209fc9, so you can go off of master now. I also merged a fix for some rare deadlocks, but that's a different issue. I believe we're aiming for a new tag in the coming days depending on a couple PRs, so hopefully that comes out soon.
Let me know if you're still seeing some memory leaks!
The process running for about 12 hours, then I force it to close all the sessions, after several hours the process was still holding 7GB memory. I have saved the heap file, it's almost the same from the begening, I have also checked the goroutines, looks quite clean.
I feel like it might related to something inside ion-sfu which might accidentally hold something that prevent the object to get collected, how to debug that?
Activity
[-]Possible memory leak on nack poll[/-][+]Possible memory leak on nack package[/+]Qizot commentedon Jul 18, 2025
I've observed the same problem. Can't really pin-point any problems in the code itself, maybe it has something to do with the
sync.Poolitself?tubzby commentedon Jul 18, 2025
@Qizot Althogh I havn't fixed it yet, it's quite possible that
PeerConnectionor something related were hold by App layer by accident.By hold I mean keep a reference or never close it.
Qizot commentedon Jul 18, 2025
I mean I experience the same issue. I've checked all the app code several times and the only potential leak must be in some libraries (unless I lost my sanity along the way).
It's not like I'm leaking huge number of memory, I have just 1:1 calls and on average I leak ~30KB per session which would be couple of packets at most but with thousands of sessions it adds up and drains all the memory after like 1,5 weeks and I need to restart the machine.
From the memory profiles I haven't seen anything big besides the nack module (I have a copied version from the repo and am using it in some other module but the code is the same) so seeing that you have a similar problem gave me a little more hope.
Not closing it probably woulld show up in the number of goroutines and in my case those are not ever-increasing.
Qizot commentedon Jul 18, 2025
I am also wondering if that has something to do maybe with the ion code? I have part of the codebase that has code taken from livekit (mainly handling of the peer connection) but as far as I know the livekit also has a quite big chunk from ion sfu.
JoTurk commentedon Jul 18, 2025
I can make a simple application to try to debug that, maybe we have a memory leak. I can try something this weekend!
tubzby commentedon Jul 18, 2025
I'm also using
ion, ifsfu.PeerLocalnever closed, theroomnever get closed, it causes leaks exactly like this, and it never increase the grouting number, you should go through your code to see if you missed to handle some ICE state change event.JoTurk commentedon Jul 18, 2025
Did you guys see that Ion is getting a reboot / remake, if you have any ideas for stuff you want to have or want to contribute please share your ideas, we're working on the draft right now pion/ion#1
tubzby commentedon Jul 18, 2025
Oh yea!
For one thing I'm now working on related to
ion: adding rtmp ingress support.Sean-Der commentedon Jul 18, 2025
@tubzby I am curious what clients don't have WHIP support (still need RTMP)?
tubzby commentedon Jul 18, 2025
@Sean-Der I am working with some industrial drone product, it support rtmp only.
JoTurk commentedon Jul 18, 2025
@tubzby I'm curious if it's e-rtmp or normal rtmp, and if it's rtmp do you transcode the audio inside the sfu?
Sean-Der commentedon Jul 18, 2025
@tubzby aye, no way around that :)
Would be great to get RTMP support into Ion. I would love to also make it all Pure Go. If we ingest AAC would be really cool if we could get a Pure Go decoder. Would be fun to work on.
tubzby commentedon Jul 18, 2025
It's normal rtmp and we don't need audio support for a drone, it's nothing but noise for a drone:)
tubzby commentedon Jul 18, 2025
Yes, H264 and ACC, pure standard.
1 remaining item
Qizot commentedon Jul 21, 2025
@joeturki
I've been doing a lot of semi-synthetic testing, and I couldn't reproduce it. It only happened on production so in fact it may have something to do with handling ICE states (with testing it is hard to reproduce what users are actually experiencing). What is more strange is that the leak is constant and is not that high per session, I would expect if we leak nack packets it would be in MBs instead of couple of KBs (but I may be wrong, maybe it happens sporadically and with prod traffic it is not noticable?).
Qizot commentedon Jul 22, 2025
Actually @tubzby might have been right about not properly closing something. I doubt it have anything to do with the interceptor itself. I've just checked the garbage collection of my session entity and for very little amount of sessions it doesn't get cleaned up.
JoTurk commentedon Jul 22, 2025
I tried for a bit and i didn't find anything, maybe we have something that is hard to close / clean? keep us updated
Qizot commentedon Aug 7, 2025
The package indeed is not leaking. Found a bug on my side with a leaking goroutine (custom congestion control) that was keeping a reference to the peer connection, effectively keeping the interceptor.
JoTurk commentedon Aug 9, 2025
Thank you for the update <3
tubzby commentedon Sep 25, 2025
@joeturki Sorry to bring this up, I have observed from
go tool pprofthatsync.Poolin this crate consumed 1832MB of memory, with only 5 tracks uploading, from the code it should be only:5 * 1024(max packet per track) * 1460(MTU)~ 7.5MB.If memory consumption is that large, I'm leaking tracks/pcs, am I correct?
Qizot commentedon Sep 25, 2025
@tubzby
sync.Poolon its own is doing garbage collection (or rather let's garbage collection claim some objects) so the memory leaked is in the objects that something else is holding. Are you sure you are not leaking some goroutines? For me even small amount (like 100) greatly contributed to the overall memory usage.tubzby commentedon Sep 25, 2025
@Qizot, I have checked the goroutines, nothing unusual.
philipch07 commentedon Dec 1, 2025
@tubzby @Qizot @paragonov I fixed a memory leak in the nack package in #386. Please let me know if it fixes the problem. Thanks!
tubzby commentedon Dec 2, 2025
@philipch07 Ok, I have switched to this branch pch07/fix-nack-deadlocks
philipch07 commentedon Dec 2, 2025
@tubzby I just merged the branch in 1209fc9, so you can go off of master now. I also merged a fix for some rare deadlocks, but that's a different issue. I believe we're aiming for a new tag in the coming days depending on a couple PRs, so hopefully that comes out soon.
Let me know if you're still seeing some memory leaks!
tubzby commentedon Dec 4, 2025
The process running for about 12 hours, then I force it to close all the sessions, after several hours the process was still holding 7GB memory. I have saved the heap file, it's almost the same from the begening, I have also checked the goroutines, looks quite clean.
I feel like it might related to something inside ion-sfu which might accidentally hold something that prevent the object to get collected, how to debug that?
goutines:
tubzby commentedon Dec 25, 2025
With the help of AI, finally I have figured out that the problem was caused by mis-management of PeerConnection, in my case:
If anyone still has this kind of problem, I'll suggest add
runtime.AddCleanupto debug alloc/collect event ofPeerConnectionif you can.We just happend to be here because this repo allocates the most amount of memory :)
JoTurk commentedon Dec 25, 2025
great news, glad you were able to find your issue, yeah we tried hard to find anything in Pion :)