-
Notifications
You must be signed in to change notification settings - Fork 64
Description
The code transmitting "ready!" assumes that it may never receive a ready signal from the opposite side when it is ready.
Normally, this is OK, and the flow is roughtly:
(A) comes online, sends "ping"
(B) not online yet, "ping" lost.
(B) comes online, sends "ping"
(A) receives B's ping; ready=true; sends "pong"
(B) receives A's pong; ready=true
However, this assumption can fail when A+B come online around the same time:
(A) comes online, sends "ping"
(B) comes online, sends "ping"
(B) receives A's ping; ready=true; sends "pong"
(A) receives B's ping; ready=true; sends "pong"
(B) receives A's pong but is ready throws exception
(A) receives B's pong but is ready throws exception
Notably, this can happen because there's no guarrantee of a single thread of execution across windows/frames/web-worker, and even if there were, there is no guarrantee that execution of a postMessage handler is immediately after the sending of a message - there may simply be non-stop execution or other event handers which cause (B) to come online before the message is handled.
Fix: don't throw an exception when this happens.