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

How do Zones and SES play together? #11

Open
erights opened this issue Mar 27, 2016 · 1 comment
Open

How do Zones and SES play together? #11

erights opened this issue Mar 27, 2016 · 1 comment

Comments

@erights
Copy link
Collaborator

erights commented Mar 27, 2016

At https://esdiscuss.org/topic/fwd-are-zones-global-state-do-they-provide-a-dangerous-communications-channel we argue that they play together perfectly well. But it is a subtle enough argument that we may have overlooked something. We need to reexamine this argument carefully, possibly formalizing it, so that we can either find a flaw or become confident that it is correct.

@benjamingr
Copy link

I might be missing something obvious but I think the conclusion (you can't pass messages through the zone global) is pretty obvious since you can't persist it in any way, even if you set it through an explicit .wrap call by the time someone else gets it it gets changed to their context.

Assume A and B, two players that want to pass a message in JavaScript, the only way they can communicate through zones (Assuming Zone is frozen except for .current which only gets set through wrap/run calls).

If A sets Zone.current through calling wrap/run, that can only affect the call stack inside that Zone.current call. If B ever gets to execute it means that either:

  • B is running in the global context, in which all zones have been cleared so the call stack has been restored (this can be proven more formally inductively on the number of contexts entered) - Zone.current is the global zone - and A can't communicate anything.
  • B is running a callback, that callback was wrapped with a Zone.run/wrap (or implicitly):
    • then it must have been inside one of B's contexts (formal proof - inductively, showing that wrapping preserves the B-ness of the context). This requires some more formality but it should be easy.

Basically, every time A executes or gets to set/unset the zone it also must unset the zone and restore it back - this stems from the definition of the zone spec.

Zones are perfectly safe with frozen realms.

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

2 participants