Skip to content

SharedWorker: Implement SharedWorker constructor reuse - #45088

Merged
Taym95 merged 9 commits into
servo:mainfrom
Taym95:sharedworker-constructor-reuse
Jun 16, 2026
Merged

Taym95 merged 9 commits into
servo:mainfrom
Taym95:sharedworker-constructor-reuse

Conversation

@Taym95

@Taym95 Taym95 commented May 22, 2026 •

Copy link
Copy Markdown
Member

Add SharedWorker lookup and matching using storage key, constructor origin, constructor URL, name, type, credentials, extended lifetime, and secure_context state

Testing: more SharedWorker WPT test are passing now.

part of #7458

@Taym95
Taym95 requested a review from gterzian as a code owner May 22, 2026 20:40
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 22, 2026

@TimvdLippe TimvdLippe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am having a hard time understanding how your changes match the specification. I see you added the spec text (which is good!) but then I don't seem to be able to match it to what you wrote. Additionally, it seems like we are synchronously running steps that should run asynchronously instead in step 11.

Maybe Gregory is a better reviewer for this change?

@servo-highfive servo-highfive added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-awaiting-review There is new code that needs to be reviewed. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels May 23, 2026

@gterzian gterzian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a general architectural comment for now.

@gterzian

gterzian commented Jun 1, 2026 •

Copy link
Copy Markdown
Member

So re the crash we're seeing in CI, I think we just need to do what dedicated workers do, which is a pity because it means we keep going in the direction of making this a kind of semi-shared dedicated worker, but that is as good as it gets for now I think.

So see how workers are tracked, and then do the same with shared workers, instead of dropping their join handle.

@servo-highfive servo-highfive added the S-needs-rebase There are merge conflict errors. label Jun 2, 2026
Taym95 added 4 commits June 2, 2026 23:42
Add constructor-side SharedWorker lookup and matching using storage key, constructor origin, constructor URL, name, type, credentials, extended lifetime, and secure_context state

Signed-off-by: Taym Haddadi <[email protected]>
Signed-off-by: Taym Haddadi <[email protected]>
@Taym95
Taym95 force-pushed the sharedworker-constructor-reuse branch from 1f0beb9 to ac0d072 Compare June 2, 2026 22:03
@servo-highfive servo-highfive removed the S-needs-rebase There are merge conflict errors. label Jun 2, 2026
Signed-off-by: Taym Haddadi <[email protected]>

@gterzian gterzian left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So the current find_or_claim_shared_worker seems very complicated(and I am not sure how it works, although I could make more efforts to understand it if you think it is the right way forward).

What I meant earlier was to just use a condvar and then if the state is Creating, wait on the condvar until it is created; that makes the logic bulletproof and simple, but blocking, although it doesn't block longer then it takes to create a worker, which would take time anyway, and the actual contention should rarely happen.

So literally I just meant something like https://doc.rust-lang.org/std/sync/struct.Condvar.html#examples (but wait on the worker being created).

Such a simple setup seems like the right way forward, because doing anything more complicated is likely to lead to more work (maybe intermittency) and will have to be thrown away anyway when a proper manager is introduced later.

@Taym95

Taym95 commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

So the current find_or_claim_shared_worker seems very complicated(and I am not sure how it works, although I could make more efforts to understand it if you think it is the right way forward).

What I meant earlier was to just use a condvar and then if the state is Creating, wait on the condvar until it is created; that makes the logic bulletproof and simple, but blocking, although it doesn't block longer then it takes to create a worker, which would take time anyway, and the actual contention should rarely happen.

So literally I just meant something like https://doc.rust-lang.org/std/sync/struct.Condvar.html#examples (but wait on the worker being created).

Such a simple setup seems like the right way forward, because doing anything more complicated is likely to lead to more work (maybe intermittency) and will have to be thrown away anyway when a proper manager is introduced later.

makes sense, I was trying to avoid blocking by queuing pending connections in the Creating state, but I agree that it makes the temporary script side registry more complicated than it needs to be, let me give Condvar a try.

@Taym95
Taym95 dismissed TimvdLippe’s stale review June 3, 2026 11:03

Gregory took over the review.

@gterzian gterzian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Couple more comments on the condvar logic.

@gterzian gterzian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can also address those intermittent crashes at #45509 (review) in this PR (or a follow-up, but writing it now).

@gterzian gterzian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with some minor points to address.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jun 15, 2026
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 16, 2026
Signed-off-by: Taym Haddadi <[email protected]>
@Taym95
Taym95 enabled auto-merge June 16, 2026 14:42
@Taym95
Taym95 added this pull request to the merge queue Jun 16, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 16, 2026
Merged via the queue into servo:main with commit c426ae0 Jun 16, 2026
31 checks passed
@Taym95
Taym95 deleted the sharedworker-constructor-reuse branch June 16, 2026 17:30
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants