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

fix(@libp2p/webrtc): close data-channel on muxer stream end #1976

Merged

Conversation

Marcel-G
Copy link
Contributor

#1895

Problem

RTCDataChannels are not properly closed after the stream ends. They stay in an open state and eventually the browser will not be able to create more RTCDataChannels with the following error:

Uncaught (in promise) DOMException: Failed to execute 'createDataChannel' on 'RTCPeerConnection': RTCDataChannel creation failed

Solution

Close data channels when the stream ends.

@achingbrain
Copy link
Member

achingbrain commented Aug 16, 2023

CI has become very sad - could this be because the WebRTC data channel is now being closed before any queued data has been sent?

This is usually what the "Error: stream ended before 1 bytes became available" error means.

@Marcel-G Marcel-G marked this pull request as draft August 17, 2023 06:58
@Marcel-G Marcel-G force-pushed the fix/webrtc-datachannel-memory-leak branch from 44e0c88 to 8cc07e5 Compare August 17, 2023 08:31
@Marcel-G Marcel-G marked this pull request as ready for review August 17, 2023 08:51
@Marcel-G Marcel-G changed the title fix(webrtc): close data-channel on stream finish fix(webrtc): close data-channel on muxer stream end Aug 18, 2023
@marcus-pousette
Copy link
Contributor

Would be great if this could be part of next release. This would perhaps also solve a related issue

@maschad maschad requested a review from a team September 4, 2023 14:29
@achingbrain achingbrain changed the title fix(webrtc): close data-channel on muxer stream end fix(@libp2p/webrtc): close data-channel on muxer stream end Sep 5, 2023
@achingbrain achingbrain merged commit 7517082 into libp2p:master Sep 5, 2023
18 checks passed
@Marcel-G Marcel-G deleted the fix/webrtc-datachannel-memory-leak branch September 5, 2023 15:20
@achingbrain
Copy link
Member

This PR needs a followup:

  1. Perhaps close the datachannel in the receiver as well for safety
  2. Add tests that assert we can open/close a large amount of streams
  3. Maybe figure out how to assert that WebRTC DataChannels are closed correctly - they are scoped to the calling context so they'll need to be exposed externally somehow and cleaned up from however they are exposed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants