FastRTC unable to create new connection due to missing relay and srlf candidates in the answer

#3
by adnan-ahmed - opened

When using Stream with custom ICE servers (STUN/TURN), the configuration is not consistently applied to the RTCPeerConnection. This results in intermittent WebRTC connection failures due to missing srflx and relay ICE candidates in the SDP answer.
Environment

FastRTC version: 0.0.27
aiortc version: 1.11.0
Python version: 3.11
Deployment: Docker container on AWS EC2

Current Behavior
ICE server configuration passed to Stream() is intermittently ignored during RTCPeerConnection creation. The SDP answers sometimes contain all candidate types (host, srflx, relay), but other times only contain host candidates, causing connection failures for clients outside the local network.

SDP with working config (connection succeeds):
a=candidate:... 10.0.189.221 47848 typ host a=candidate:... 44.194.175.153 57096 typ srflx a=candidate:... 44.197.215.14 63412 typ relay

SDP with missing config (connection fails):
a=candidate:... 172.18.0.3 40798 typ host (no srflx or relay candidates)

Expected Behavior
ICE server configuration should be consistently applied to every RTCPeerConnection, ensuring srflx and relay candidates are always gathered when STUN/TURN servers are configured.
Steps to Reproduce

Create a Stream with ICE server configuration:

ice_servers_config = {
"iceServers": [
{"urls": ["stun:stun.l.google.com:19302"]},
{
"urls": ["turn:my-turn-server.com:3478?transport=udp"],
"username": "user",
"credential": "pass",
},
]
}

stream = Stream(
handler=handler_factory(),
modality="audio-video",
mode="send-receive",
rtc_configuration=ice_servers_config,
server_rtc_configuration=ice_servers_config,
concurrency_limit=500,
)

Make multiple WebRTC connection attempts from a browser client
Observe that some SDP answers contain srflx/relay candidates while others don't

Additional Context

TURN server is self-hosted coturn on AWS EC2
TURN allocation succeeds when tested directly with aiortc
Restarting the container temporarily resolves the issue, suggesting possible state accumulation

Sign up or log in to comment