Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ready message has a race condition #26

Open
EamonNerbonne opened this issue Apr 9, 2014 · 0 comments
Open

ready message has a race condition #26

EamonNerbonne opened this issue Apr 9, 2014 · 0 comments

Comments

@EamonNerbonne
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant