Skip to content

Integrate service worker manager thread - #11727

Merged
bors-servo merged 2 commits into
servo:masterfrom
creativcoder:swmanager
Jul 18, 2016
Merged

bors-servo merged 2 commits into
servo:masterfrom
creativcoder:swmanager

Conversation

@creativcoder

@creativcoder creativcoder commented Jun 12, 2016 •

Copy link
Copy Markdown
Contributor

  • There are tests for these changes at my gh-pages branch to test the instantiation of service workers by their manager, but will need to discuss how that would integrate into master.

Changes:

  • Introduces a ServiceWorkerManager, which maintains an map of registered service workers as well as a map of active workers keyed by their scope_url.
  • Adds the initialization of ServiceWorkerManager, at the script::init(), which makes it available as a single entity listening for requests from different script threads.
  • Adds a timeout thread in serviceworkerglobalscope, which terminates the workers, after a timeout of 60 secs, thereby removing it from the active workers list.
  • Adds the matching of scope urls, in longest prefix way rather than path structural way, according to spec.
  • Make ServiceWorkerManager, the holder of network sender, instead of script thread, so it can send CustomResponse.

This change is Reviewable

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @asajeffrey: components/constellation/pipeline.rs, components/constellation/constellation.rs
  • @KiChjang: components/script/dom/worker.rs, components/script/lib.rs, components/script/serviceworker_manager.rs, components/script/dom/serviceworkerregistration.rs, components/script/dom/serviceworker.rs, components/script/Cargo.toml, components/script/dom/workerglobalscope.rs, components/script/dom/dedicatedworkerglobalscope.rs, components/script_traits/script_msg.rs, components/script_traits/script_msg.rs, components/script_traits/lib.rs, components/script_traits/lib.rs, components/script/script_thread.rs, components/script/dom/abstractworker.rs, components/script/dom/serviceworkerglobalscope.rs

@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 12, 2016
@creativcoder

Copy link
Copy Markdown
Contributor Author

@jdm r?

@@ -4,75 +4,43 @@

@creativcoder creativcoder Jun 12, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jdm As suggested about serviceworkerglobalscopes, not having the parent sender, the worker instance, and the parent runtime, i have removed the code, which had interactions with them. But will need advice on the run_with_memory_reporting thing when listening for events, which needs a parent_sender. I think, at the very minimum, we will need a ServiceWorker object instance, to facilitate dispatching of events to them, but how would i send a ServiceWorker object to service worker manager from the script_thread ? I am open to improving this PR. Thoughts ?

@creativcoder

Copy link
Copy Markdown
Contributor Author

The build succeeded but travis gives this The command "bash etc/ci/check_no_unwrap.sh" exited with 1.

@Ms2ger

Ms2ger commented Jun 12, 2016

Copy link
Copy Markdown
Contributor

r? @jdm

@highfive highfive assigned jdm and unassigned Ms2ger Jun 12, 2016
@jdm

jdm commented Jun 12, 2016

Copy link
Copy Markdown
Member

Check_no_unwrap fails if there are unwrap calls detected in constellation code.

@highfive

Copy link
Copy Markdown

New code was committed to pull request.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #11745) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jun 15, 2016
@creativcoder
creativcoder force-pushed the swmanager branch 3 times, most recently from f8a337c to f794ad4 Compare June 17, 2016 17:24
@creativcoder

Copy link
Copy Markdown
Contributor Author

@jdm I removed the need for sending navigation message from constellation to script thread. You were right, it was redundant. Instead, am matching for the load_url, when the script thread has to interact with network sender, and during that match I am sending, the the ScopeThings to constellation, which further sends it to SW-Manager, to activate the respective worker.
I have a question:
For the origin http://localhost:8000, navigating to http://localhost:8000/dashboard-page.html, by clicking a button, will reuse the same script thread which was created for http://localhost:8000; right ?

@jdm

jdm commented Jun 17, 2016

Copy link
Copy Markdown
Member

Same-origin navigation do not reuse the script thread right now, unfortunately.

@creativcoder

Copy link
Copy Markdown
Contributor Author

@jdm okay, so that's the reason, why manual click registering a sw for http://localhost:8000/dashboard-page.html, and then navigating to that url, does not activate the sw-dashboard.js, because the registration was stored in previous script thread.

@jdm

jdm commented Jun 17, 2016

Copy link
Copy Markdown
Member

This is why we need the actual registration data (note: orthogonal to the JS object) to be stored in the SW manager.

@creativcoder
creativcoder force-pushed the swmanager branch 3 times, most recently from c398863 to d88d3b3 Compare June 22, 2016 18:38
@creativcoder

creativcoder commented Jun 23, 2016 •

Copy link
Copy Markdown
Contributor Author

@jdm I made the changes. The ScopeThings is stored in SW-manager, but then again, we have to remove its entry in manager when passing it to run_serviceworker_scope, since it cannot be cloned (as there is a devtools receiver there) and i wonder, at what place the devtools_receiver could be decoupled from ScopeThings. It is hooked to the WorkerGlobalScopeInit Suggestions ?

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #11735) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jun 23, 2016
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jul 12, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jul 12, 2016
@creativcoder

creativcoder commented Jul 13, 2016 •

Copy link
Copy Markdown
Contributor Author

Test logs shows this (60 tests timeout):

▶ TIMEOUT [expected PASS] /_mozilla/css/borders_a.html
  │ 
  └ Shutting down the Constellation after generating an output file or exit flag specified

  ▶ TIMEOUT [expected PASS] /_mozilla/css/canvas_radial_gradient_a.html
  │ 
  └ Shutting down the Constellation after generating an output file or exit flag specified

  ▶ TIMEOUT [expected PASS] /_mozilla/css/data_img_a.html
  │ 
  └ Shutting down the Constellation after generating an output file or exit flag specified

and this ( there are more instances of this kind of Timeout)

▶ TIMEOUT [expected PASS] /_mozilla/mozilla/canvas/drawimage_html_image_1.html
  │ 
  │ updating composition_request (NewFrameTree)
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ got ready to save image query, result is DocumentLoading
  │ sent response
  │ resetting ready_to_save_state!
  │ composition_request is already CompositeNow(NewFrameTree)
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ got ready to save image query, result is DocumentLoading
  │ sent response
  │ resetting ready_to_save_state!
  │ composition_request is already CompositeNow(NewFrameTree)
  │ got ready to save image query, result is DocumentLoading
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ sent response
  │ resetting ready_to_save_state!
  │ composition_request is already CompositeNow(NewFrameTree)
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ got ready to save image query, result is DocumentLoading
  │ sent response
  │ resetting ready_to_save_state!
  │ composition_request is already CompositeNow(NewFrameTree)
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ got ready to save image query, result is DocumentLoading
  │ sent response
  │ resetting ready_to_save_state!
  │ composition_request is already CompositeNow(NewFrameTree)
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ got ready to save image query, result is DocumentLoading
  │ sent response
  │ resetting ready_to_save_state!
  │ composition_request is already CompositeNow(NewFrameTree)
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ got ready to save image query, result is DocumentLoading
  │ sent response
  │ resetting ready_to_save_state!
  │ composition_request is already CompositeNow(NewFrameTree)
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ got ready to save image query, result is DocumentLoading
  │ sent response
  │ resetting ready_to_save_state!
  │ composition_request is already CompositeNow(NewFrameTree)
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ got ready to save image query, result is DocumentLoading
  │ sent response
  │ resetting ready_to_save_state!
  │ composition_request is already CompositeNow(NewFrameTree)
  │ not ready to composite: NotReadyToPaintImage(JustNotifiedConstellation)
  │ got ready to save image query, result is DocumentLoading
  │ sent response

@jdm Could that be an intermittent ? Most Timeouts appear to happen when rendering images or canvas related tests. Full Log

@jdm

jdm commented Jul 13, 2016

Copy link
Copy Markdown
Member

Have you run those tests locally? I suspect it's a reproducible problem.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #12441) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jul 15, 2016
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Jul 16, 2016
@jdm

jdm commented Jul 17, 2016 •

Copy link
Copy Markdown
Member

I did some debugging and figured out the problem. When we're running reftests (ie. using --output foo.png or --exit), we block on retrieving image data in the layout thread (https://dxr.mozilla.org/servo/source/components/layout/context.rs#136). Meanwhile, the compositor asks the constellation if it's time to take a screenshot, so the constellation sends a synchronous query to the layout thread to get some information about what the most recent operation was (https://dxr.mozilla.org/servo/source/components/constellation/constellation.rs#2043). Meanwhile, the HTTP loader thread for the image sends a message to the constellation to ensure that any service worker is properly handled, but that message sits in a queue until after the constellation is finished dealing with the request from the compositor.

We've got a deadlock between the layout, constellation, and HTTP loader threads in this case. The easiest way to break it is to make the HTTP loader communicate directly with the service worker manager, rather than passing through the constellation as an intermediary.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jul 17, 2016
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jul 18, 2016
@creativcoder

Copy link
Copy Markdown
Contributor Author

@jdm Oh, great. Thanks for giving time in investigating this. Updated with the required changes, and tested the wpt-tests locally and there are no timeouts now. Let me know if the latest commit looks good to you.

@jdm

jdm commented Jul 18, 2016

Copy link
Copy Markdown
Member

@bors-servo: r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit eff3e01 has been approved by jdm

@highfive highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jul 18, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit eff3e01 with merge 513811f...

@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants