Unity-Technologies / com.unity.webrtc

WebRTC package for Unity
Other
738 stars 186 forks source link

[BUG]: Erratic ICE with multiple parallel PeerConnections #1017

Open dfischer23 opened 5 months ago

dfischer23 commented 5 months ago

Package version

3.0.0-pre.7

Environment

* OS: MacOSX Sonoma 14.2.1
* Unity version: 2022.3.13.f1

Steps To Reproduce

  1. clone this Reproduction Project
  2. modify the number of parallel DataChannelTest to 10
  3. start project in Editor or build app.

Current Behavior

ICE setup won't finish and/or Editor or built App crashes with ~10 or more parallel PeerConnection setups

Expected Behavior

Every parallel DataChannelSample should be able to set up a connection just like in the example or when there is only one. Adding more instances should not affect operation.

Anything else?

In real life, i have a project that successfully sets up multiple peer-to-peer Audio connections using the "perfect negotiation" pattern and a proprietary signalling server. It becomes very unreliable as i increase the number of connections.

In this Reproduction Project, I use the simple DataChannel example but set it up a number of times in parallel. ICE/Session setup starts to fail as I increase the number of parallel setups- 1 to 3 mostly work, above it starts failing with seemingly random failure modes.

The number of parallel setups can be adjusted on the "DataChannelTest" object.

To check if the 'operations chain' is the culprit, i modified the test to cache all IceCandidates until the local and remote descriptions are setup (in the buffer-candidates branch. While the "not ready to use the remote candidate.." and similar messages go away, the apps still crash with many connections.

Another small observation which might be relevant: as i increase the number of parallel setups, it seems the number of ICE host candidates in individual setups also increases. In one test run, i saw the first setup had 4 candidates (normal), the second 5, then 6 etc until the 10th had 14! They've referenced different TCP ports, so it's not a simple doubling..

karasusan commented 3 months ago

memo: WRS-505