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

Add code to allocate agent clusters. #4617

Merged
merged 12 commits into from
Sep 9, 2019
Merged

Conversation

dtapuska
Copy link
Contributor

@dtapuska dtapuska commented May 13, 2019

Store shared agent clusters in the browsing context group via a map of
scheme & registrable domain.

Hook the document initialization methods to obtain a similar-orgin
window agent.

Fixes #4361


/browsers.html ( diff )
/browsing-the-web.html ( diff )
/infrastructure.html ( diff )
/webappapis.html ( diff )

@dtapuska
Copy link
Contributor Author

@annevk @domenic Here is a crack at the allocating agent clusters. It closely matches the allocation that we have planned for Chrome.

I've made a change to what Anne provided as a rough sketch around naming the items shared agent clusters. Because I presume there will be agent clusters that will exist but not be shared, and they wouldn't be in this list. For example I'd expect that we could implement the feature policy in these steps and just return early providing a new agent cluster for everyone that has the policy set.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I like this approach, except that I think we need to refactor navigate so that documents are not the source of truth, but only an end result. I'd rather not further enshrine the weird "document's JavaScript API comes alive later" model.

source Outdated Show resolved Hide resolved
source Outdated
@@ -89103,6 +89115,66 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
in particular among which <span data-x="agent">agents</span> the backing data of
<code>SharedArrayBuffer</code> objects can be shared.</p>

<p>A <span>browsing context group</span> has associated <dfn data-export="">shared agent
clusters</dfn> (a <span data-x="ordered map">map</span> of <span>agent cluster key</span> to
<span>agent cluster</span>).</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to export "shared agent clusters"? Also, if you have a different strategy in mind, it seems we don't need the agent cluster key abstraction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the export. I do think the definition of the agent cluser key makes it clear it is based on the registrable domain.

source Outdated Show resolved Hide resolved
@domenic
Copy link
Member

domenic commented May 14, 2019

Does it seem feasible to do this incrementally, by first fixing agent clusters, then fixing the ordering of Document allocation? Tying them together seems to increase the likelihood that only you will be able to ultimately take this on...

@littledan
Copy link
Contributor

It's great to see this logic written out explicitly. Such an approach might also help us to be more explicit on the JS side, so cc @syg @lars-t-hansen who wrote much of that spec text.

@annevk
Copy link
Member

annevk commented May 15, 2019

I think I can live with document being created first and letting the bugs around that stay with us a little longer. However, we should get this to a stage whereby we no longer have to define the declarative setup around similar-origin window agents (i.e., can remove "same-agent Window objects") and whereby allocation of a new realm happens in the context of a particular agent such that it's appended to the agent's set of realms. (The current PR appears to do this in the wrong order, too.)

If we mark #4361 as fixed we should also file a follow-up for workers, though maybe there's something similar already tracking that.

@dtapuska
Copy link
Contributor Author

@annevk Ok, I've adjusted my approach. I've pulled the determination of the sandbox flags and the origin before the document is created. This allows me to create the agent before the realm is created and pass the agent into that. Make sense?

@annevk
Copy link
Member

annevk commented May 24, 2019

Unfortunately, I'm having a hard time trying to understand this patch. E.g., determining the origin only really works when you're creating a popup or some such. Otherwise, when there's no creator origin, you're still highly dependent on existing infrastructure, right? I also miss the aspects I hinted at in my previous comment, i.e., why do we now have both new imperative-style and old declarative-style allocation of agents and agent clusters? We should be able to remove some of that, no? (Not the worker parts yet, but some of the window parts.)

@dtapuska
Copy link
Contributor Author

@annevk I've rebased this on the navigation algorithm now. Can you take a look at it now?

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't really verified if all the things happen in the right order and whether all callsites are modified appropriately.

source Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
@annevk
Copy link
Member

annevk commented Jul 15, 2019

I think you forgot to push.

@dtapuska
Copy link
Contributor Author

I think you forgot to push.

It wasn't quite ready when I left Friday. I perhaps am using git incorrectly because I'd really like to respond to comments all at once. I've been able to do that on a review but not responding to individual feedback. Anyways I've pushed the latest changes now.

@domenic
Copy link
Member

domenic commented Jul 15, 2019

It's a bit unintuitive, but you can submit your own "review" of type "comment" (as opposed to "approved" or "changes requested" types) and that allows drafting and batch-submission of replies.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By and large this is correct, but there's a number of important edge cases we need to get right. Some we might have to defer though as TC39 hasn't really resolved the issues on their end.

source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated
false.</p></li>
<p class="note">Two <code>Window</code> objects that have the same <span>agent</span> does
not indicate they can share data with each other, only that it is possible. Two windows
might only share data if they are <span>same origin-domain</span>.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this sentence is wrong on multiple grounds due to postMessage(). And if you make it synchronous access it's still somewhat suspect due to SharedArrayBuffer I think?

Maybe say something about not necessarily being able to directly access all objects created in such a Window object's realm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adjusted this and put a link to IsPlatformObjectSameOrigin

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "might be" mean?

@@ -90393,6 +90357,68 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
in particular among which <span data-x="agent">agents</span> the backing data of
<code>SharedArrayBuffer</code> objects can be shared.</p>

<p>A <span>browsing context group</span> has associated <dfn>agent cluster map</dfn> (a <span
data-x="ordered map">map</span> of <span>agent cluster key</span> to <span>agent
cluster</span>).</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to clarify here that we only hold these agent clusters weakly, i.e., user agents are responsible for collecting them when it is deemed that nothing can access them anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated
<li>
<p>Let <var>realm execution context</var> be the result of <span>creating a new JavaScript
realm</span> with the following customizations:</p>
realm</span> in <var>agent</var> with the following customizations:</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you haven't modified this similarly to how @domenic suggested above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

@dtapuska dtapuska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL, I think I've addressed all the open issues. I've fixed merge conflicts via a forced push.

source Show resolved Hide resolved
source Outdated
<li>
<p>Let <var>realm execution context</var> be the result of <span>creating a new JavaScript
realm</span> with the following customizations:</p>
realm</span> in <var>agent</var> with the following customizations:</p>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I only have a number of nits left. @domenic should probably also have a final look.

source Outdated
<span>relevant settings object</span>'s <span
data-x="concept-settings-object-origin">origin</span>.</p></li>
<p class="note">Two <code>Window</code> objects that have the same <span>agent</span> does not
indicate they can directly access all objects created in each others realms. Two windows might be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there not be an apostrophe after "others"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it should be "each other's". Changed.

source Outdated
<span>relevant settings object</span>'s <span
data-x="concept-settings-object-origin">origin</span>.</p></li>
<p class="note">Two <code>Window</code> objects that have the same <span>agent</span> does not
indicate they can directly access all objects created in each others realms. Two windows might be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of "Two windows" maybe use "They" as otherwise it's rather informal and not directly clear objects are meant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

source Outdated
data-x="concept-settings-object-origin">origin</span>.</p></li>
<p class="note">Two <code>Window</code> objects that have the same <span>agent</span> does not
indicate they can directly access all objects created in each others realms. Two windows might be
required to be in <span>same origin-domain</span>, see <span>IsPlatformObjectSameOrigin</span>.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use "required" in a note. Maybe say "They would have to be same origin-domain, see ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got really confused before I realized that yes, there is only one similar-origin window agent per agent cluster. There can be more stuff, but it's all non-window agents. So I added one commit, on top of my editorial ones, that tries to make the situation clearer. Please take a look and let me know if I'm on the right track.

Otherwise, I have one TODO about allocating the agent and defining "similar-origin window agent" more correctly.

@@ -90397,6 +90374,70 @@ import "https://example.com/foo/../module2.mjs";</code></pre>
in particular among which <span data-x="agent">agents</span> the backing data of
<code>SharedArrayBuffer</code> objects can be shared.</p>

<p>A <dfn data-export="">scheme-and-site</dfn> is a <span>tuple</span> of a <span
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just me, or would it make more sense to call it scheme-and-domain??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called it site due to https://url.spec.whatwg.org/#host-same-site. "scheme-and-registrable-domain" might work, but "domain" seems too ambiguous.

source Outdated
data-x="obtain-browsing-agent-cluster">obtaining a browsing context agent cluster</span> with
<var>group</var> and <var>clusterKey</var>.</p></li>

<li><p>Return <var>agentCluster</var>'s <span>similar-origin window agent</span>.</p></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This links to the definition of the concept of similar-origin window agent. But it's used as a field on agentCluster.

I think the intention here is something like "return the single agent contained in agentCluster". (The ES spec seems to define agent clusters to be be "sets of agents".) Similarly below, in "obtain a browsing context agent cluster".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agentCluster would have multiple agents. It would only have a single window agent though, the other agents will be for workers or worklets. I was trying to phrase something like "return agentCluster's single window agent".

</ol>

<p>A <dfn data-export="">similar-origin window agent</dfn> is an <span>agent</span> whose
[[CanBlock]] is false. </p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like a sufficient definition; in particular there are others with [[CanBlock]] of false. I think instead you want something like "A similar-origin window agent is an agent created during the course of the following algorithm:" and then inside the algorithm you create a new "agent".

That new agent should get all its fields set. In particular:

  • [[CanBlock]] to false
  • [[Signifier]] to ... a new unique value?
  • [[CandidateExecution]] to a new empty candidate execution
  • [[LittleEndian]], [[IsLockFree1]], and [[IsLockFree2]] at the implement's discretion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus far we only defined values that are different given that ECMAScript doesn't define concrete agent allocation. So I think continuing with only specifying [[CanBlock]] is fine, but we should probably use "new" in there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what ECMAScript really needs to define. It's just a record with a bunch of fields; you can create those pretty easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Domenic I've written what you suggested. Anne I tried to add "new" in there and it felt that Domenic's proposal was more natural.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found more nits. I might be able to push this over the finish line once we're all aligned.

source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
</ol>

<p>A <dfn data-export="">similar-origin window agent</dfn> is an <span>agent</span> whose
[[CanBlock]] is false. </p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus far we only defined values that are different given that ECMAScript doesn't define concrete agent allocation. So I think continuing with only specifying [[CanBlock]] is fine, but we should probably use "new" in there.

source Show resolved Hide resolved
source Show resolved Hide resolved
dtapuska and others added 2 commits August 28, 2019 14:02
Store shared agent clusters in the browsing context group via a map of
scheme & registrable domain.

Hook the document initialization methods to obtain a similar-orgin
window agent.

Fixes whatwg#4361
dtapuska and others added 9 commits August 28, 2019 14:02
- Remove extra comments
- Add period
- Remove useless text
- Add formalism around creation of Window Agent
- Remove window agent definition
- shared agent clusters -> agent cluster map
Biggest thing is relocating the definition of "similar-origin window agent" to the agents section instead of agent cluster section
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looks good to me!! @dtapuska can you sanity-check my latest changes? I'm ready to pull this in now if you are.

Copy link
Contributor Author

@dtapuska dtapuska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this

@domenic domenic merged commit 0404472 into whatwg:master Sep 9, 2019
@domenic domenic added the topic: agent The interaction with JavaScript's agent and agent cluster concepts label Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: agent The interaction with JavaScript's agent and agent cluster concepts
Development

Successfully merging this pull request may close these issues.

Imperative allocation of agent clusters
4 participants