6

I'm using WebRTC to facilitate peer to peer connections for a multiplayer browser game. One peer is chosen as the host to which other client peers will connect. The host peer runs both client & server logic. All clients (including the host client) connect to the host's server via WebRTC.

Occasionally I'm seeing this host client -> host server WebRTC connection establishment failing for an unknown reason. The host client & server logic are running in the same tab / Javascript VM so it may help to visualise this setup as some kind of loopback connection within the page.

A failed connection establishment flow goes as follows:

Failed WEBRTC Connection Flow

At the end of this flow (which takes ~5seconds) both the Client & Host RTCPeerConnections are in the following state (and never transition from here):

RTCPeerConnection.iceConnectionState: "disconnected"
RTCPeerConnection.connectionState: "failed"
RTCPeerConnection.iceGatheringState: "complete"

The Offer, Answer & ICE Candidates exchanged in this flow look like this:

Client Offer

{"type":"offer","sdp":"v=0\r\no=- 8829702333684311109 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=msid-semantic: WMS\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\na=ice-ufrag:67dh\r\na=ice-pwd:YxRQGGpaV6OkuogZxjhA3W1l\r\na=ice-options:trickle\r\na=fingerprint:sha-256 D2:13:F7:B5:3B:69:33:5F:40:ED:D9:52:2F:83:EC:B5:5A:D4:7E:0D:1A:08:F5:39:E9:02:AB:4E:7E:6B:50:D9\r\na=setup:actpass\r\na=mid:0\r\na=sctp-port:5000\r\na=max-message-size:262144\r\n"}

Host Answer

{"type":"answer","sdp":"v=0\r\no=- 657100447142081608 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=msid-semantic: WMS\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\nb=AS:30\r\na=ice-ufrag:4eiM\r\na=ice-pwd:JlAUG/0qxZpEsOMT0neKg7LK\r\na=ice-options:trickle\r\na=fingerprint:sha-256 DC:EB:66:5F:C9:73:A9:96:37:7C:A8:21:8E:81:6C:8D:1B:78:47:45:39:76:83:CD:D2:4F:E9:94:72:C7:FD:3B\r\na=setup:active\r\na=mid:0\r\na=sctp-port:5000\r\na=max-message-size:262144\r\n"}

Client ICE Candidates

  1. {"candidate":"candidate:585712035 1 udp 2113937151 0322602a-bcc1-41b4-96e3-963022b99529.local 55860 typ host generation 0 ufrag 67dh network-cost 999","sdpMid":"0","sdpMLineIndex":0}
  2. {"candidate":"candidate:1593308690 1 udp 2113939711 c34a088f-0835-4e78-aa33-7b4206079a3c.local 55861 typ host generation 0 ufrag 67dh network-cost 999","sdpMid":"0","sdpMLineIndex":0}
  3. {"candidate":"candidate:842163049 1 udp 1677729535 5.64.56.196 55860 typ srflx raddr 0.0.0.0 rport 0 generation 0 ufrag 67dh network-cost 999","sdpMid":"0","sdpMLineIndex":0}
  4. null

Host ICE Candidates

  1. {"candidate":"candidate:585712035 1 udp 2113937151 0322602a-bcc1-41b4-96e3-963022b99529.local 54514 typ host generation 0 ufrag 4eiM network-cost 999","sdpMid":"0","sdpMLineIndex":0}
  2. {"candidate":"candidate:1593308690 1 udp 2113939711 c34a088f-0835-4e78-aa33-7b4206079a3c.local 54515 typ host generation 0 ufrag 4eiM network-cost 999","sdpMid":"0","sdpMLineIndex":0}
  3. {"candidate":"candidate:842163049 1 udp 1677729535 5.64.56.196 54514 typ srflx raddr 0.0.0.0 rport 0 generation 0 ufrag 4eiM network-cost 999","sdpMid":"0","sdpMLineIndex":0}
  4. null

Browser

Chrome Version 79.0.3945.130.

dbotha
  • 1,501
  • 4
  • 20
  • 38
  • Have you tried running a Wireshark capture on the loopback interface to spot the difference between a successful connection and a failing one? That's my first port of call. I have observed similar behaviour to yours with my own app but not it's not browser-to-browser. In that case the sporadic failures are down to the DTLS handshake. If the server side has a large certificate it results in fragmented UDP packets which don't play nice. I think the certificate from Chrome is small so again that might not be the cause. – sipsorcery Feb 22 '20 at 20:41
  • Good call, I will examine the traffic with Wireshark in the next day or so and post the results. Interestingly this issue does seem to only arrise on Chrome - I've switch to Firefox & Safari over the last few days in an attempt to reproduce with no luck whatsoever. – dbotha Feb 24 '20 at 10:03

0 Answers0