Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

WebRTC logs STUN binding request timed out while gathering candidates

Your error

STUN binding request timed out.1 more line it can show

Fix it fast

Most common cause, 1 of 3

One local interface cannot reach the server while the others can

Treat 701 as a warning, not a failure.

Fix
const types = new Set();
pc.addEventListener("icecandidate", (e) => {
  if (e.candidate) types.add(e.candidate.type);
  else if (!types.has("srflx") && !types.has("relay")) {
    console.warn("no server candidates: check STUN/TURN reachability");
  }
});
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

'STUN binding request timed out' is the errorText of icecandidateerror code 701: a binding request from one local network interface got no STUN or TURN reply. If srflx candidates still appear, the call works and the message is noise. If none appear, UDP is blocked or the server URL is wrong. Applies to Chrome and other libwebrtc browsers, PeerJS 1.5.5.

  • Applies to Chrome and other libwebrtc-based browsers, PeerJS 1.5.5, RTCPeerConnection iceServers configuration
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Log the gathered candidates next to the ICE errors on the same connection. With PeerJS, attach the listeners to call.peerConnection or conn.peerConnection. If srflx candidates appear despite the error, read cause 1; if gathering completes with none, test causes 2 and 3.

Run this first
pc.addEventListener("icecandidate", (e) => {
  if (e.candidate) console.log("candidate:", e.candidate.type);
  else console.log("gathering complete");
});
pc.addEventListener("icecandidateerror", (e) => {
  console.log("ice error:", e.errorCode, e.url, e.errorText);
});

Then find the line you see in this list and open its fix:

  1. 1One local interface cannot reach the server while the others canThe 701 error is logged, but srflx candidates are still gathered and the call or data channel connects
  2. 2The network blocks UDP to STUN, so no server candidates appearGathering completes with only host candidates on an office or school network, and the same code yields srflx candidates on a phone hotspot
  3. 3The STUN or TURN URL in your config is wrong or the server is downEvery 701 error names the same url, and even the hotspot test produces no srflx candidates

What does the error look like?

  • STUN binding request timed out.
  • icecandidateerror errorCode 701

Cause 1 of 3

One local interface cannot reach the server while the others can

You seeThe 701 error is logged, but srflx candidates are still gathered and the call or data channel connects

Check

libwebrtc sends a STUN binding request from each local network it gathers on, and reports STUN binding request timed out, with its server-not-reachable code, for every one that gets no answer. An interface with no route to the server, for example a VPN or virtual adapter, fails that way while another interface succeeds. MDN notes that the 701 value is reported once per server URL during gathering.

Check
pc.addEventListener("icegatheringstatechange", () => {
  console.log("gathering:", pc.iceGatheringState);
});

Fix

Treat 701 as a warning, not a failure. Log it with the server URL, and raise an alert only when gathering reaches complete without any srflx or relay candidate, or when the connection state ends in failed.

Fix
const types = new Set();
pc.addEventListener("icecandidate", (e) => {
  if (e.candidate) types.add(e.candidate.type);
  else if (!types.has("srflx") && !types.has("relay")) {
    console.warn("no server candidates: check STUN/TURN reachability");
  }
});

Verify

Connections succeed while the 701 lines stay in the log only as warnings, and the alert never fires on a normal network.

Verify
console.log(pc.connectionState);

Confirmed by webrtc.googlesource.com

Did this fix it?

Cause 2 of 3

The network blocks UDP to STUN, so no server candidates appear

You seeGathering completes with only host candidates on an office or school network, and the same code yields srflx candidates on a phone hotspot

Check

Server reflexive (srflx) candidates come from the STUN server's answer. When a firewall drops outgoing UDP, every binding request times out and peers on different networks have no usable address pair. The TURN guide on webrtc.org states that most WebRTC apps need a relay server, since peers outside one local network often cannot open a direct path.

Check
console.log([...types]); // from the set built in cause 1

Fix

Add a TURN server. Next to the UDP URL, list a turns: URL with transport=tcp, the TLS-over-TCP form defined for TURN URIs, so clients that cannot use UDP still have a relay path. In PeerJS, pass the list in the config option; it replaces the default servers.

Fix
const peer = new Peer({
  config: {
    iceServers: [
      { urls: "stun:stun.l.google.com:19302" },
      {
        urls: ["turn:turn.example.com:3478?transport=udp", "turns:turn.example.com:443?transport=tcp"],
        username: "user",
        credential: "secret",
      },
    ],
  },
});

Verify

Run a probe connection with iceTransportPolicy set to relay on the blocked network. It logs relay candidates, which proves the TURN server answers from there.

Verify
const test = new RTCPeerConnection({ iceServers, iceTransportPolicy: "relay" });
test.createDataChannel("probe");
await test.setLocalDescription(await test.createOffer());

Confirmed by webrtc.org

Did this fix it?

Cause 3 of 3

The STUN or TURN URL in your config is wrong or the server is down

You seeEvery 701 error names the same url, and even the hotspot test produces no srflx candidates

Check

The urls value must use the STUN URI form, stun:host or stun:host:port, with 3478 as the default port. A typo in the host name, an http:// prefix, a closed port or a self-hosted server that is not running makes every interface time out against that one URL. With PeerJS, a custom config also removes the default STUN and TURN servers, so a single bad entry leaves nothing that works.

Check
console.log(JSON.stringify(pc.getConfiguration().iceServers, null, 2));

Fix

Correct the URL to the documented scheme and port, and confirm the server listens on that port. Keep a second, known-good STUN entry in the list while you fix your own server.

Fix
iceServers: [
  { urls: "stun:stun.example.com:3478" },
  { urls: "stun:stun.l.google.com:19302" },
]

Verify

The 701 errors for that URL stop, and srflx candidates appear on an open network.

Verify
console.log([...types].includes("srflx"));

Confirmed by rfc-editor.org

Did this fix it?

How do I stop it coming back?

  • Ship a TURN server with a turns: URL on port 443 from the first release, because some users will always sit behind UDP-blocking networks.
  • Record candidate types per session in your analytics, so a rise in sessions without srflx or relay candidates shows up as a server or network problem.
  • Keep STUN and TURN URLs in one config file and check them at app start with a short relay-only probe.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, SessionBird.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.