Commit abf2ac5e authored by Philipp Hancke's avatar Philipp Hancke Committed by Commit Bot

webrtc wpt: avoid race conditions

Avoids race conditions by first setting the remote description before setting the local description.
ICE will only start checking (and generating candidates) after SLD.
Also avoids the case that candidates arrive before a remote description is set since its always set first.

BUG=960718

Change-Id: I38e69f625c8aba82711422812fc9634af647d056
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1632470
Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com>
Reviewed-by: default avatarHarald Alvestrand <hta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663871}
parent 38a61786
...@@ -222,7 +222,11 @@ function coupleIceCandidates(pc1, pc2) { ...@@ -222,7 +222,11 @@ function coupleIceCandidates(pc1, pc2) {
} }
// Helper function for doing one round of offer/answer exchange // Helper function for doing one round of offer/answer exchange
// between two local peer connections // between two local peer connections.
// Calls setRemoteDescription(offer/answer) before
// setLocalDescription(offer/answer) to ensure the remote description
// is set and candidates can be added before the local peer connection
// starts generating candidates and ICE checks.
async function doSignalingHandshake(localPc, remotePc, options={}) { async function doSignalingHandshake(localPc, remotePc, options={}) {
let offer = await localPc.createOffer(); let offer = await localPc.createOffer();
// Modify offer if callback has been provided // Modify offer if callback has been provided
...@@ -230,9 +234,9 @@ async function doSignalingHandshake(localPc, remotePc, options={}) { ...@@ -230,9 +234,9 @@ async function doSignalingHandshake(localPc, remotePc, options={}) {
offer = await options.modifyOffer(offer); offer = await options.modifyOffer(offer);
} }
// Apply offer // Apply offer.
await localPc.setLocalDescription(offer);
await remotePc.setRemoteDescription(offer); await remotePc.setRemoteDescription(offer);
await localPc.setLocalDescription(offer);
let answer = await remotePc.createAnswer(); let answer = await remotePc.createAnswer();
// Modify answer if callback has been provided // Modify answer if callback has been provided
...@@ -240,7 +244,7 @@ async function doSignalingHandshake(localPc, remotePc, options={}) { ...@@ -240,7 +244,7 @@ async function doSignalingHandshake(localPc, remotePc, options={}) {
answer = await options.modifyAnswer(answer); answer = await options.modifyAnswer(answer);
} }
// Apply answer. Note: localPc should enter stable state first. // Apply answer.
await localPc.setRemoteDescription(answer); await localPc.setRemoteDescription(answer);
await remotePc.setLocalDescription(answer); await remotePc.setLocalDescription(answer);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment