Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PeerConnection should drop reference to datachannel when it's closed #2672

Closed
Tracked by #2704
sukunrt opened this issue Feb 9, 2024 · 0 comments · Fixed by #2696
Closed
Tracked by #2704

PeerConnection should drop reference to datachannel when it's closed #2672

sukunrt opened this issue Feb 9, 2024 · 0 comments · Fixed by #2696

Comments

@sukunrt
Copy link
Member

sukunrt commented Feb 9, 2024

Your environment.

  • Version: 3.x

What did you do?

libp2p is a peer to peer networking library used in IPFS among other things. We are using webrtc in go-libp2p to provide connectivity to nodes running in the browser. For our use, we create a peer connection and open lots of data channels over the life time of the connection.

Currently the reference to datachannels is not dropped when a datachannel is closed. PeerConnection.sctpTransport.dataChannels always has a reference to the existing data channels which has a reference to the sctp stream. Over the life time of the connection this leads to a lot of memory usage.

What did you expect?

I expected the memory used by the datachannel to be garbage collected.

Proposed fix

Datachannel has an OnClose handler. This handler should remove the datachannel from the sctpTransport
To preserve existing behaviour we should:

  1. Only keep the reference to the ID that was used on the datachannel
  2. Create a DataChannelStats object for the stats on the datachannel to preserve collectStats behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant