[webrtc-pc] Can onicecandidate fire before SLD.then(code)? (#2574)

henbos has just created a new issue for https://github.com/w3c/webrtc-pc:

== Can onicecandidate fire before SLD.then(code)? ==
ICE candidates of callee can be generated in response to pc.setLocalDescription(answer).

Both processing the result of an SLD and processing ice candidates being generated and the event fires happens by queuing a task in response to the SLD operation. So one would assume, that SLD happens first and ice candidate events fires second.

So clearly code1 would execute before code2 in "pc.onicecandidate = e => { code2 }; pc.SLD.then(code1);"

**_OR WOULD IT?!_**

While p is resolved first and the event is fired second, p.then(code) only runs at the (start/end?) of the task execution cycle.

In Chrome (see [bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1127309#c2)) I believe the promise is resolved first, then the onicecandidate event handler runs, then the promise's then code runs. **Is this spec-compliant or not?**

**This causes issues.** Example:

```
// Setup
caller.onicecandidate = e => { callee.addIceCandidate(e.candidate) };
callee.onicecandidate = e => { caller.addIceCandidate(e.candidate) };

// ...

// In response to an offer from caller:
const answer = await callee.createAnswer();
await callee.setLocalDescription(answer);
await caller.setRemoteDescription(answer);
```

What happens:
1. callee.SLD's promise gets resolved first, but the promise.then() code is not exected yet, i.e. we do not start to do caller.SRD just yet.
2. callee.onicecandidate fires and caller.addIceCandidate happens, which doesn't work because we haven't performed caller.SRD yet.
3. caller.SRD is executed because this is what happens after "await".


Please view or discuss this issue at https://github.com/w3c/webrtc-pc/issues/2574 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 11 September 2020 13:28:56 UTC