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

WebRTC Transport creating large number of DataChannels when used with Multiplexer #1895

Closed
justin0mcateer opened this issue Jul 25, 2023 · 3 comments
Labels
need/triage Needs initial labeling and prioritization

Comments

@justin0mcateer
Copy link

justin0mcateer commented Jul 25, 2023

  • Version:
    0.45.9

  • Platform:

  • Subsystem:
    WebRTC Transport
    Yamux / Mplex

Severity:

Medium

Description:

When connecting two browsers directly via a CircuitRelayV2 server, I am seeing stable signaling (a single WebRTC connection 'stays up'), but a large number (~60) of DataChannels are created, each only sending a very small number of bytes (<100 bytes in nearly all cases). As an additional bit of information, Yamux opens 60 DataChannels and Mplex seems to open 20, but they both continue adding new DataChannels every five minutes. I don't think this would create an real issue in the short-term, but for a long running application (like ours) it will almost certainly be problematic fairly quickly.

According to this article the number of DataChannels supported by the browser are much, much less than the theoretical maximum (as little as 128) for FireFox as of ~2 years ago. Assuming nothing has changed, this would exhaust the number of available DataChannels in several hours.
https://tensorworks.com.au/blog/webrtc-stream-limits-investigation/

~60 DataChannels, mostly created at once:
image

<100 Bytes sent on each DataChannel:
image

The number of DataChannels continues to grow, in my configuration a new DataChannel is opened approximately every five minutes. All the DataChannels appear to remain open (at least in excess of 15 minutes)

New DataChannels opened every five minutes (exactly):
image

Old DataChannels stay open:
image

Steps to reproduce the error:

  • Establish a Browser to Browser WebRTC connection with the WebRTC Transport
  • Open the 'brave://webrtc-internals' (or 'chrome://webrtc-internals')
  • Observe the large and ever growing number of DataChannels
@justin0mcateer justin0mcateer added the need/triage Needs initial labeling and prioritization label Jul 25, 2023
@maschad maschad self-assigned this Jul 26, 2023
@maschad maschad moved this to 🤨Needs Investigation in js-libp2p Jul 26, 2023
@justin0mcateer
Copy link
Author

Just as a follow up, left to run overnight, this does hit the maximum number of DataChannels Chrome will allow (512).

@maschad maschad removed their assignment Aug 14, 2023
@Marcel-G
Copy link
Contributor

Marcel-G commented Aug 16, 2023

@justin0mcateer I am reasonably confident that js-libp2p webrtc-transport does not actually close data channels when it's done with them. That seems like a bug and will eventually result in running out of data channels. Chrome throws the following error when it can't create any more:

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

Could you please try with these changes to js-libp2p #1976

@justin0mcateer
Copy link
Author

Sorry for the late feedback, I see this has been merged.

I did try this patch and it improved things. However, we ended up also adding the same change on the 'onEnd' handler of incoming connections. I think it is needed it cases where the connection is severed uncleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/triage Needs initial labeling and prioritization
Projects
Archived in project
Development

No branches or pull requests

3 participants