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 P2P connections are slow to open #599

Closed
gpauloski opened this issue Jul 18, 2024 · 0 comments
Closed

WebRTC P2P connections are slow to open #599

gpauloski opened this issue Jul 18, 2024 · 0 comments
Assignees
Labels
bug Error, flaw, or fault that causes unexpected behavior

Comments

@gpauloski
Copy link
Collaborator

Describe the problem.

I noticed on my WSL machine that the test suite suddenly became very slow sometime in the last month or so. Using --durations, every test using P2P was taking a multiple of 5 seconds (5, 10, or 20s in the worst case).

Inspecting the call stack for the slow part led me down this path:

RTCPeerConnection.setLocalDescription
RTCPeerConnection.__gather
RTCIceGatherer.gather
Connection.gather_candidates
Connection.get_component_candidates
server_reflective_candidate

The server_reflective_candidate() performs the STUN check as a coroutine with a 5s timeout determined by Connection.get_component_candidates(). I verified reducing this timeout reduces the WebRTC connection time.

Oddly, every other machine I tested on did not have this problem so it must be something related to the networking configuration of this one device. I also tried:

  • Older versions of aiortc/aioice.
  • Updating system packages.
  • Using mirrored instead of NAT networking for WSL.
  • Other STUN servers.

The issues seems to be lack of trickle ICE in aioice (related: pion/webrtc#460). aioice does not have trickle ICE support (aiortc/aioice#4) so I'm not sure there is much to be done about this, but I am documenting it here for reference and others that run into the issue.

This script reproduces the slowdown (but worked fine on other devices):

import asyncio
import aioice
from aiortc.rtcicetransport import connection_kwargs
from aiortc.rtcconfiguration import RTCIceServer

async def main():
    servers = [RTCIceServer("stun:stun.cloudflare.com:3478")]
    ice_kwargs = connection_kwargs(servers)
    connection = aioice.Connection(ice_controlling=False, **ice_kwargs)
    await connection.gather_candidates()

asyncio.run(main())
$ time python t.py
real    0m5.162s
user    0m0.152s
sys     0m0.000s

How did you install ProxyStore?

$ pip install proxystore

ProxyStore Version

0.7.0

Python Version

3.12

OS and Platform

Ubuntu

@gpauloski gpauloski added the bug Error, flaw, or fault that causes unexpected behavior label Jul 18, 2024
@gpauloski gpauloski self-assigned this Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Error, flaw, or fault that causes unexpected behavior
Projects
None yet
Development

No branches or pull requests

1 participant