Skip to content

Conversation

@mrobinson
Copy link
Member

ScriptThreads start with an initial Pipeline, but that Pipeline
should not be used for any ScriptThread global data as a
ScriptThread can have any number of Pipelines that come and go.
There's no architectural reason why a ScriptThread should be
associated with only a single WebView.

This change makes it so that the ScriptThread no longer uses the
PipelineId and the WebViewId of the initial Pipeline to initialize
itself. Instead a ScriptEventLoopId is used to uniquely identify every
ScriptThread in both the ScriptThread and the Constellation.
The remaining use was for crash reporting. Now when a crash happens, it
launches the sad tab in all WebViews that depeneded on that
ScriptThread.

This is a change which should allow simplifying the way that
EventLoops/ScriptThreads are started in the Constellation, which
will be handled in a followup.

Testing: This shouldn't change behavior except in the case where a
ScriptThread is used in more than a single WebView, which should work
properly now. I tested this change manually by running servoshell in
multiprocess mode while causing a panic to happen due to a null pointer
dereference. The sad tab appeared after this change, so things seem to work
properly still. Testing crashes is tricky with the way we test servo now.

@mrobinson mrobinson requested a review from gterzian as a code owner November 27, 2025 11:30
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 27, 2025
) -> JoinHandle<()> {
let webview_id = WebViewId::installed();
let event_loop_id = ScriptEventLoopId::installed()
.expect("A DedicatedWorker should always be run from a ScriptThread context");
Copy link
Member

Choose a reason for hiding this comment

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

What about the case where a worker is launched from another worker?

Copy link
Member Author

Choose a reason for hiding this comment

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

This expect message is a bit confusing, so I'll update it. Essentially, the thread should either be a ScriptThread or a dedicated worker launched from another ScriptThread in which case the ScriptEventLoopId should also be installed. That said, maybe the ScriptEventLoopId should also be installed.

.expect("Thread spawning failed")
}

pub(crate) fn webview_id(&self) -> Option<WebViewId> {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we use an Option here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, this doesn't need to be an Option at all. I'll address it.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Nov 27, 2025
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 27, 2025
`ScriptThread`s start with an initial `Pipeline`, but that `Pipeline`
should not be used for any `ScriptThread` global data as a
`ScriptThread` can have any number of `Pipeline`s that come and go.
There's no architectural reason why a `ScriptThread` should be
associated with only a single `WebView`.

This change makes it so that the `ScriptThread` no longer uses the
`PipelineId` and the `WebViewId` of the initial `Pipeline` to initialize
itself. Instead a `ScriptEventLoopId` is used to uniquely identify every
`ScriptThread` in both the `ScriptThread` and the `Constellation`.
The remaining use was for crash reporting. Now when a crash happens, it
launches the sad tab in all `WebView`s that depeneded on that
`ScriptThread`.

This is a change which should allow simplifying the way that
`EventLoop`s/`ScriptThread`s are started in the `Constellation`, which
will be handled in a followup.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
@mrobinson mrobinson added this pull request to the merge queue Nov 27, 2025
@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 Nov 27, 2025
Merged via the queue into servo:main with commit 08aad55 Nov 27, 2025
29 checks passed
@mrobinson mrobinson deleted the script-thread-id branch November 27, 2025 14:22
@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 Nov 27, 2025
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.

3 participants