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

Imperative allocation of agent clusters #4361

Closed
annevk opened this issue Feb 13, 2019 · 5 comments · Fixed by #4617
Closed

Imperative allocation of agent clusters #4361

annevk opened this issue Feb 13, 2019 · 5 comments · Fixed by #4617
Labels
topic: agent The interaction with JavaScript's agent and agent cluster concepts

Comments

@annevk
Copy link
Member

annevk commented Feb 13, 2019

This is a follow-up to #4198. The browsing context group concept is added by #4350, but to properly clarify the lifetime of objects, we'll need to imperatively allocate them. In particular, objects might lose their direct connection to a browsing context (e.g., when you remove an <iframe>), but that doesn't mean they're outside the scope of the agent they were created in (e.g., when you keep a reference to a WindowProxy object while you remove that <iframe>).

(Alternatively we could perhaps give everything a pointer to the browsing context group, but that doesn't seem like a good architecture, in particular because nothing in ECMAScript really supports that kind of notion.)

This is the setup I have for this thus far:


A browsing context group has associated agent clusters (a map of agent cluster key/agent cluster).

An agent cluster key is an origin or a scheme-and-site. A scheme-and-site is a tuple of a scheme and a domain.

To obtain an agent cluster key, given an origin origin, run these steps:

  1. If origin is an opaque origin, then return origin.

  2. If origin's host's registrable domain is null, then return origin.

  3. Return (origin's host's scheme, origin's host's registrable domain).

To obtain a similar-origin window agent, given a browsing context group group and agent cluster key key, run these steps:

  1. Let agentCluster be the result of obtaining a browsing context agent cluster with group and key.

  2. If agentCluster does not contain an agent, then add a new similar-origin window agent to it. (ECMAScript does not define the layout of agent clusters unfortunately.)

  3. Return agentCluster's similar-origin window agent.

To obtain a browsing context agent cluster, given a browsing context group group and agent cluster key key, run these steps:

  1. If group's agent clusters[key] does not exist, then set group's agent clusters[key] to a new agent cluster. (ECMAScript does not define allocating agent clusters unfortunately.)

  2. Return group's agent clusters[key].


Feedback appreciated.

cc @mystor @farre @rniwa @creis @domenic

(This intentionally does not cover workers. They can use a simpler allocation setup that can be sorted as part of #4339.)

@rniwa
Copy link

rniwa commented Feb 22, 2019

but that doesn't mean they're outside the scope of the agent they were created in

It's true that the script from one agent X may hold onto an object O from another agent Y but if Y dies, there is no more execution context or stack left for Y. We can't, for example, start evaluating or dispatching events in Y.

At least in WebKit, each document has its own script execution context only when it's associated with a frame (i.e. a browsing context) and when it gets detached from a frame, its script execution context and therefore the agent associated with it is dead.

I'd be curious to know how Gecko is architected here.

@annevk
Copy link
Member Author

annevk commented Feb 22, 2019

How can you hold onto objects cross-agent? The only thing that's cross-agent is a Shared Data Block per ECMAScript. Do you mean cross-realm/global? Also, to clarify, the case OP is talking about is same-origin <iframe>s.

@rniwa
Copy link

rniwa commented Feb 22, 2019

Yeah, I'm talking about cross-realm/global case. In general, the life cycle of an agent is tied to its document having a frame. As soon as it loses the frame, the agent is gone.

@annevk
Copy link
Member Author

annevk commented Feb 23, 2019

I don't understand. In the case of a document having a same-origin framed document, both documents have a global. That global points to a single (shared) agent. Removing the frame doesn't get rid of the agent.

@annevk annevk added the topic: agent The interaction with JavaScript's agent and agent cluster concepts label Feb 25, 2019
dtapuska added a commit to dtapuska/html that referenced this issue 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 whatwg#4361
dtapuska added a commit to dtapuska/html that referenced this issue May 23, 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 whatwg#4361
dtapuska added a commit to dtapuska/html that referenced this issue May 27, 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 whatwg#4361
dtapuska added a commit to dtapuska/html that referenced this issue May 27, 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 whatwg#4361
dtapuska added a commit to dtapuska/html that referenced this issue Jul 11, 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 whatwg#4361
dtapuska added a commit to dtapuska/html that referenced this issue Jul 29, 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 whatwg#4361
dtapuska added a commit to dtapuska/html that referenced this issue Jul 29, 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 whatwg#4361
dtapuska added a commit to dtapuska/html that referenced this issue Aug 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 whatwg#4361
dtapuska added a commit to dtapuska/html that referenced this issue Aug 28, 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 whatwg#4361
@domenic
Copy link
Member

domenic commented Sep 9, 2019

This is nearing completion in #4617. Although the title of the issue is pretty general, seeming to cover all types of agent clusters, it sounds like we should be closing this issue and using #4339 to track worker and worklet stuff.

domenic pushed a commit that referenced this issue Sep 9, 2019
Previously, the spec vaguely noted that all agents and agent clusters
must be allocated at the appropriate time.

With this change, similar-origin window agents are allocated
imperatively during document and browsing context creation, along with
their corresponding agent clusters. The agent clusters are stored in the
appropriate browsing context group, via a map keyed by scheme and
registrable domain.

Fixes #4361. Further work on imperative agent/agent cluster allocation,
specifically for workers and worklets, is tracked in #4339.
zcorpan pushed a commit that referenced this issue Nov 6, 2019
Previously, the spec vaguely noted that all agents and agent clusters
must be allocated at the appropriate time.

With this change, similar-origin window agents are allocated
imperatively during document and browsing context creation, along with
their corresponding agent clusters. The agent clusters are stored in the
appropriate browsing context group, via a map keyed by scheme and
registrable domain.

Fixes #4361. Further work on imperative agent/agent cluster allocation,
specifically for workers and worklets, is tracked in #4339.
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 a pull request may close this issue.

3 participants