-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Implement Worker.prototype.terminate() #5846
Conversation
Adds support for terminating DOM workers. A new ScriptMsg::Terminate was added to notify the WorkerGlobalScope/DedicatedWorkerGlobalScope to stop processing events and shut down. A closing flag was added to WorkerGlobalScope per the spec. Additionally, a closing flag was added to dom::worker::Worker to ensure no further events are dispatched to the onmessage handler. The change to the wpt WorkerTerminate.js is a patch for the broken Worker_terminate_event_queue test (asserts 10001 == 10000). Resolves servo#4427
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @jdm (or someone else) soon. |
Critic review: https://critic.hoppipolla.co.uk/r/4802 This is an external review system which you may optionally use for the code review of your pull request. In order to help critic track your changes, please do not make in-place history rewrites (e.g. via |
@@ -100,6 +103,10 @@ impl Worker { | |||
data: StructuredCloneData) { | |||
let worker = address.to_temporary().root(); | |||
|
|||
if worker.r().closing.get() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec specifies to empty the event/task queue associated with the worker as to not deliver further events to the onmessage
handler. Without a synchronous way to affect the DedicatedWorkerGlobalScope
, I resorted to these short-circuiting checks to prevent messages from being delivered. I keep thinking about this because it's kind of ugly. Does someone have any perspective on a cleaner way to achieve that behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gecko appears to differentiate between normal events in the worker thread's queue and what it calls a ControlRunnable. The run loop in their worker prioritizes the control events and handles at most one normal event on an iteration. We could implement something similar by adding a control channel and moving to a select model for the loop.
I commented on critic. |
I left a couple of comments/questions in reply. Do reviewers get notified of replies from critic, or should I ping from the issue? |
The comments arrive in email form; no ping necessary. |
I fixed all of the issues on critic except escaping a long running JS handler. Interrupting JS execution in this case requires a call to JS_RequestInterrupt from |
The latest changes add support for killing a blocking script in the worker. Such capability requires a reference to the JSRuntime in It might be good to have a second channel for workers as well. I ended up needing to buffer ScriptMsgs outside of the receiver. This wouldn't even be a problem if there was a dedicated channel for control messages. The code in |
global_object_for_js_object and global_object_for_js_context shared a lot of common code that has been moved into global_object_for_js_global.
Please rebase on master. |
Rebased as #6652 |
Adds support for terminating DOM workers.
ScriptMsg::Terminate
was added to notify the WorkerGlobalScope/DedicatedWorkerGlobalScope to stop processing events and shut down. A closing flag was added to WorkerGlobalScope per the spec.Additionally, a closing flag was added to
dom::worker::Worker
to ensure no further events are dispatched to theonmessage
handler.The change to the wpt WorkerTerminate.js is a patch for the broken Worker_terminate_event_queue test (asserts 10001 == 10000).
Resolves #4427