Description
Sockets opened in ICEGatherer seem to be leaked. They will never be closed even when the PeerConnections are closed. Finally, my server becomes unavailable with too many open files
error.
I've investigated into webrtc's source code, and found that CandidateBase.close()
is an no-op. Of course, it is because tokio's UdpSocket does not provide close()
. Despite all, the sockets should be closed when it is dropped. Therefore, I guess that the socket is not dropped.
RTCPeerConnection
holds Arc<PeerConnectionInternal>
and there are other holders too. In v0.2.1, the peerconnection has no problem, dropped well. However, other holders seems not to drop it. I have no idea where the others are, but internal_rtcp_writer
(peer_connection.rs, line 170) or pci
(peer_connection.rs, line 1163, 1345, 1393) may have created reference cycle.
If possible, those references should be replaced by std::sync::Weak
to break the cycle. Pion or other webrtc libraries written in garbage-collected languages may not suffer from this issue because the GC can detect and free those circular references well. Because Rust does not have one, we should use weak references to avoid this problem. It will also fix other memory leaks too.