Skip to content

Conversation

domenic
Copy link
Member

@domenic domenic commented Aug 27, 2025

It turns out these concepts are identical, and it was just very hard to tell. Proof:

  • "protected" implies "actively needed": immediate from their existing definitions.

  • "actively needed" implies "protected": the key is that for an actively needed worker, "the worker's ports" is never empty, so step 3 will always return true. In particular, for dedicated workers, their implicit MessagePort can never be removed from "the worker's ports", since there is no exposed MessagePort object that could be transferred or close()ed or garbage collected. And shared workers are always protected.

Stated another way, despite the complicated definition of "protected", it is not possible to have a worker that is "actively needed" but not "protected". The extra clause about outstanding timers, database transactions, or network connections is redundant.

This is a follow-up to e9ccb97. The text prior to that revision also supports this conclusion.


It would be good to get a check on this from worker experts like @yoshisatoyanagisawa, @asutherland, or @fergald. In particular I'm curious if there was an underlying implementation distinction here, which the spec was trying to make but failed to do so.


/workers.html ( diff )

It turns out these concepts are identical, and it was just very hard to tell. Proof:

* "protected" implies "actively needed": immediate from their existing definitions.

* "actively needed" implies "protected": the key is that for an actively needed worker, "the worker's ports" is never empty, so step 3 will always return true. In particular, for dedicated workers, their implicit MessagePort can never be removed from "the worker's ports", since there is no exposed MessagePort object that could be transferred or close()ed or garbage collected. And shared workers are always protected.

Stated another way, despite the complicated definition of "protected", it is not possible to have a worker that is "actively needed" but not "protected". The extra clause about outstanding timers, database transactions, or network connections is redundant.

This is a follow-up to e9ccb97. The text prior to that revision also supports this conclusion.
@domenic domenic added clarification Standard could be clearer topic: workers labels Aug 27, 2025
@domenic
Copy link
Member Author

domenic commented Aug 27, 2025

Actually I think this is wrong. The case of "actively needed" but not "protected" might be: a dedicated worker doing a bunch of computation, with no outstanding timers/database transactions/etc., whose corresponding Worker object got garbage collected.

Closing, and will open a different clarification PR to point that out.

@domenic domenic closed this Aug 27, 2025
domenic added a commit that referenced this pull request Aug 27, 2025
After e9ccb97, the specification contained an incorrect statement in the non-normative note stating that every worker that is actively needed is protected. This is not correct (see also #11598). Expand the non-normative note with more details and examples on the relationships between actively needed, protected, and permissible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Standard could be clearer topic: workers
Development

Successfully merging this pull request may close these issues.

1 participant