[webrtc-pc] Race condition in enqueue an operation

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

== Race condition in enqueue an operation ==
In step 6 of enqueue an operation:

> 6. If the length of [[operations]] is exactly 1, execute operation.

This result in race condition with synchronous code following call to RTCPeerConnection methods. That is, if length of the operation queue is 1, the operation is executed _before_ the next line of synchronous code; But if the length of operation queue is > 1, the operation is executed _after_ the current microtask return to the event loop. This can result in code having unexpected behavior depending on whether the internal operation queue is empty or not when the operation is enqueued.

For example, if the next line of code is `peerconnection.close()`, then the result can be very different.

To fix this, the operation should be enqueued to the next tick if the length of operation queue is 1.

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

Received on Wednesday, 17 May 2017 08:01:06 UTC