WebRTC works on Wi-Fi, ICE fails on 4G and corporate networks: TURN over TCP and TLS 443
Calls connected at home but sat on Connecting forever for users on mobile data and office networks. STUN alone cannot get through symmetric NAT or UDP-blocking firewalls. Here is the TURN setup and the relay-only test that proved it.
Our telehealth app connected patients to clinicians in a browser. In testing everything worked: office Wi-Fi to home Wi-Fi, laptop to phone. After launch, about one call in eight never connected. The patient saw "Connecting..." until they gave up. The clinician side logged this:
[call 8f2c] iceConnectionState: checking -> failed
[call 8f2c] connectionState: connecting -> failed
Firefox users on the failing calls got a more helpful console message:
WebRTC: ICE failed, add a TURN server and see about:webrtc for more details
Failures clustered on two groups: patients on mobile data, and clinicians working from one hospital network.
Reproducing it
Tethering a laptop to a phone on mobile data and calling a second laptop on the same carrier failed every time. Calling from the hospital guest network failed every time. Home broadband to home broadband worked.
What we ruled out
Signalling. Offers, answers and candidates all arrived on both sides; the WebSocket logs showed every message. The failure happened after signalling, in connectivity checks.
Codec or permission problems. Those fail differently: a negotiation error or a missing track, not ICE moving to
failed.Our STUN server being down. Both sides gathered
srflx(server reflexive) candidates, so STUN worked. It just did not help.
Root cause
We had configured only a STUN server. STUN lets each peer learn its public address, and that is enough when at least one NAT keeps the same public mapping for every destination. Mobile carriers commonly run carrier-grade NAT with endpoint-dependent mapping, often called symmetric NAT: the public port the carrier assigns depends on where the packet is going, so the address learned from STUN is useless for talking to the other peer. The hospital network was different but just as fatal: it blocked outbound UDP entirely and only allowed TCP to ports 80 and 443 through a proxy. Neither case can be solved without a relay, and we had no TURN server.
What is happening under the hood
ICE collects candidate addresses for each peer and tries pairs of them until one works:
Candidate type | Where it comes from | Works when |
|---|---|---|
| The device's own interfaces | Both peers on the same network |
| Public address seen by a STUN server | NAT mapping is reused for other destinations |
| An address allocated on a TURN server | Almost always, if the relay is reachable |
With endpoint-dependent mapping, the port the STUN server saw is not the port the other peer will see, so srflx pairs fail. With UDP blocked, every UDP pair fails. The only remaining path is a TURN relay, and on restrictive networks it must be reachable over TCP, ideally TLS on port 443 so it looks like ordinary HTTPS to a firewall.
TURN traffic goes through your server, so it costs bandwidth. That is why you still offer host and srflx candidates: ICE prefers direct paths and only falls back to relay when it must.
Environment
Component | Version / value |
|---|---|
Clients | Chrome 141, Safari 26 on iOS 26 and macOS 26, Firefox 144 |
Signalling | WebSocket, trickle ICE |
Before fix |
|
TURN after fix | coturn 4.6 on Ubuntu 24.04, public IP, TLS certificate for |
Failing networks | Mobile data (carrier-grade NAT), hospital network (UDP blocked, TCP 80/443 only) |
Minimal reproduction
// before: STUN only
const pc = new RTCPeerConnection({
iceServers: [{ urls: 'stun:stun.example.com:3478' }],
});
On a tethered phone you can watch about:webrtc in Firefox or chrome://webrtc-internals in Chrome: candidate pairs are tried, each moves to failed, and no pair ever succeeds.
Who is affected
Any WebRTC app without TURN. How many users fail depends on your audience. Home broadband users mostly connect directly. Mobile, enterprise, school and hotel networks fail much more often. The failure is silent from the user's point of view, so it is easy to underestimate.
The fix
1. Run a TURN server reachable on UDP, TCP and TLS. We used coturn. The important parts of the config:
# /etc/turnserver.conf (excerpt)
listening-port=3478
tls-listening-port=443
external-ip=203.0.113.10
realm=turn.example.com
cert=/etc/letsencrypt/live/turn.example.com/fullchain.pem
pkey=/etc/letsencrypt/live/turn.example.com/privkey.pem
# short-lived credentials (TURN REST API style)
use-auth-secret
static-auth-secret=CHANGE_ME_LONG_RANDOM
# relay port range, opened in the cloud firewall
min-port=49160
max-port=49200
# do not let the relay reach private or loopback ranges
no-multicast-peers
denied-peer-ip=0.0.0.0-0.255.255.255
denied-peer-ip=10.0.0.0-10.255.255.255
denied-peer-ip=127.0.0.0-127.255.255.255
denied-peer-ip=169.254.0.0-169.254.255.255
denied-peer-ip=172.16.0.0-172.31.255.255
denied-peer-ip=192.168.0.0-192.168.255.255
no-cli
fingerprint
Port 443 on this host is dedicated to TURN, so it does not clash with a web server. If you must share an IP with HTTPS, put TURN on its own address instead of trying to multiplex.
2. Issue short-lived credentials from the backend. With use-auth-secret, the username is an expiry timestamp plus an id, and the password is an HMAC of the username with the shared secret. Nothing long-lived ships to the browser.
// server: GET /api/ice-servers (Node.js)
import crypto from 'node:crypto';
export function iceServersFor(userId) {
const expires = Math.floor(Date.now() / 1000) + 3600;
const username = `${expires}:${userId}`;
const credential = crypto
.createHmac('sha1', process.env.TURN_SECRET)
.update(username)
.digest('base64');
return [
{ urls: 'stun:turn.example.com:3478' },
{
urls: [
'turn:turn.example.com:3478?transport=udp',
'turn:turn.example.com:3478?transport=tcp',
'turns:turn.example.com:443?transport=tcp',
],
username,
credential,
},
];
}
3. Recover instead of hanging. When the connection goes to failed, we call pc.restartIce() once, then show a clear error with a retry button instead of an endless spinner.
Alternatives and trade-offs
A managed TURN service. Saves running servers and gives you points of presence near users. You pay per relayed gigabyte, and you still need the short-lived credential flow.
TURN on port 3478 only. Cheaper to set up but does not get through networks that only allow 443. In our data, that was most of the enterprise failures.
Forcing relay for everyone. Simplifies debugging and hides client IP addresses from the other peer, but every call then costs relay bandwidth and adds a hop of latency.
How to test the fix
The decisive test is to forbid every path except the relay. If a call connects with this setting, your TURN setup works:
const pc = new RTCPeerConnection({
iceServers: await fetch('/api/ice-servers').then((r) => r.json()),
iceTransportPolicy: 'relay',
});
We ran that from the tethered phone and from the hospital network. Then we checked which pair won:
const stats = await pc.getStats();
stats.forEach((s) => {
if (s.type === 'candidate-pair' && s.nominated && s.state === 'succeeded') {
const local = stats.get(s.localCandidateId);
console.log(local.candidateType, local.protocol, local.relayProtocol);
}
});
// relay udp tls (hospital network: allocation reached over TLS)
The official Trickle ICE sample page from the WebRTC project is also useful: paste your TURN URL and credentials and confirm that relay candidates appear for each transport.
Confirming in production
We log the winning candidate type per call. After the rollout, failed calls dropped from about 12 percent to under 1 percent. About 9 percent of calls now use a relay, almost all of them on mobile data or enterprise networks, and most of the hospital calls relay over TLS on 443. The remaining failures are users who lose connectivity entirely, which shows up as disconnected first, not as a failed without any succeeding pair.
Regression guard
A synthetic check runs every five minutes from two regions with
iceTransportPolicy: 'relay'against each TURN endpoint and alerts if no relay candidate is gathered.An alert fires if the share of calls ending in
failedrises above 2 percent in an hour.Certificate expiry for
turn.example.comis monitored like any other TLS endpoint, because an expired certificate breaks only theturns:path and is easy to miss.
Security implications
A TURN server is an open relay if you get it wrong. With long-lived static credentials embedded in the page, anyone can copy them and push traffic through your server. Short-lived HMAC credentials limit that window. The denied-peer-ip ranges stop a client from asking the relay to send packets to private addresses inside your cloud network, which would turn TURN into a way to reach internal services. Keep the coturn CLI disabled, limit the relay port range, and set quotas per user if your version supports them. Relaying also means call media passes through your infrastructure; it stays encrypted end to end with DTLS-SRTP, so the relay cannot read it.
Prevention checklist
Ship TURN from day one; STUN alone is not a production configuration.
Offer TURN over UDP, TCP and TLS on 443.
Mint short-lived TURN credentials on the server per user.
Block private and loopback ranges as relay peers.
Test every release with
iceTransportPolicy: 'relay'from a restrictive network.
References
MDN, WebRTC connectivity and ICE: https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Connectivity
MDN,
RTCPeerConnection()constructor andiceTransportPolicy: https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnectionRFC 8656, TURN: https://datatracker.ietf.org/doc/html/rfc8656
RFC 4787, NAT behavioural requirements for UDP: https://datatracker.ietf.org/doc/html/rfc4787
coturn project README and example config: https://github.com/coturn/coturn
WebRTC samples, Trickle ICE: https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
Add a label
Embed this post
<iframe src="https://hibug.me/webrtc-ice-failed-symmetric-nat-turn" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I lead security operations for engineering organisations that are too big to ignore security and too small for a large security team. That means a bit of everything: vulnerability management, logging and detection, cloud configuration reviews, phishing response and incident handling. The posts here are practical: what to set up first, what to measure, which alerts are worth waking someone for, and what to do in the first hour of an incident. Where I describe incidents, details are changed, but the mistakes and the fixes are real patterns I have seen more than once.
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.