Skip to content

Make network listener runnable cancellable - #12277

Merged
bors-servo merged 3 commits into
servo:masterfrom
cbrewster:network_listener_cancellable
Jul 8, 2016
Merged

bors-servo merged 3 commits into
servo:masterfrom
cbrewster:network_listener_cancellable

Conversation

@cbrewster

@cbrewster cbrewster commented Jul 5, 2016 •

Copy link
Copy Markdown
Contributor

This keeps scripts from executing after its script thread has been shut down.


  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive

highfive commented Jul 5, 2016

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/htmllinkelement.rs, components/script/network_listener.rs, components/script/dom/xmlhttprequest.rs, components/script/dom/htmlscriptelement.rs, components/script/dom/htmlmediaelement.rs, components/script/script_thread.rs

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

highfive commented Jul 5, 2016

Copy link
Copy Markdown

warning Warning warning

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

@jdm

jdm commented Jul 5, 2016

Copy link
Copy Markdown
Member

Here's a test that might work:

  • parent.html adds an iframe loading child.html in a cross-origin manner (to ensure a separate script thread)
  • child.html has a load event listener that appends an external script to the document
  • this script uses wptserve's network filter to delay the script's network response by one second (foo.js?pipe=trickle(d1))
  • parent.html's iframe load event removes the iframe, then finishes the test three seconds later

@cbrewster

cbrewster commented Jul 6, 2016 •

Copy link
Copy Markdown
Contributor Author

@jdm turns out, the panic only occurs if the iframe is same-origin, which seems bad since they could share the same script thread.

@cbrewster
cbrewster force-pushed the network_listener_cancellable branch 2 times, most recently from 632324b to 2246f58 Compare July 6, 2016 03:29
@cbrewster

Copy link
Copy Markdown
Contributor Author

I added a test case that fails w/o the cancellable changes.

@cbrewster
cbrewster force-pushed the network_listener_cancellable branch from 2246f58 to 0cd7688 Compare July 6, 2016 03:30
@cbrewster

Copy link
Copy Markdown
Contributor Author

I want to run a few tries on this to make sure it fixes #11703.
@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 0cd7688 with merge a4fb625...

bors-servo pushed a commit that referenced this pull request Jul 6, 2016
…r=<try>

Make network listener runnable cancellable

<!-- Please describe your changes on the following line: -->
This keeps scripts from executing after its script thread has been shut down.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] These changes fix #12048 and fix #11703 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12277)
<!-- Reviewable:end -->
@jdm

jdm commented Jul 6, 2016

Copy link
Copy Markdown
Member

If the test in question shuts down the shared script thread, that's a problem that we should be fixing :)

@cbrewster

Copy link
Copy Markdown
Contributor Author

@jdm after the iframe is removed, the page still runs fine with the test results. So I assume that means the script thread for the parent isn't shut down.

@jdm

jdm commented Jul 6, 2016

Copy link
Copy Markdown
Member

True!

@@ -0,0 +1 @@
// this script does nothing

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.

This script should call a function in the parent page which would make the test fail. Something like
window.script_executed = t.unreached_func("script executed in removed iframe") in the parent, and in the child: script_executed = parent.script_executed; then invoke script_executed() in this JS file.

@cbrewster
cbrewster force-pushed the network_listener_cancellable branch from 0cd7688 to 411acaf Compare July 6, 2016 04:26
@cbrewster

Copy link
Copy Markdown
Contributor Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 411acaf with merge 7b83970...

bors-servo pushed a commit that referenced this pull request Jul 6, 2016
…r=<try>

Make network listener runnable cancellable

<!-- Please describe your changes on the following line: -->
This keeps scripts from executing after its script thread has been shut down.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] These changes fix #12048 and fix #11703 and fix #12284 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12277)
<!-- Reviewable:end -->
@cbrewster

Copy link
Copy Markdown
Contributor Author

Well this does not seem to fix the intermittent :(

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jul 6, 2016
@jdm

jdm commented Jul 6, 2016

Copy link
Copy Markdown
Member

The backtrace of the most recent panic is coming from a DOMManipulationTask runnable, not a network one.

@cbrewster

Copy link
Copy Markdown
Contributor Author

@jdm is it possible to do something similar with that runnable?

@jdm

jdm commented Jul 6, 2016

Copy link
Copy Markdown
Member

What I'm wondering is why we're still running events for a script thread that's been shut down...

@jdm

jdm commented Jul 6, 2016

Copy link
Copy Markdown
Member

Oh, it's not the script thread that is shut down, it's a window that's had its JS context information cleared because it is not supposed to be needed any more. Bah.

@jdm

jdm commented Jul 6, 2016

Copy link
Copy Markdown
Member

There are a bunch of things in DOMManipulationTask that use Runnable which could theoretically be hooked the same way. The FireEvent and FireSimpleEvent messages would need special handling to ignore those messages if they're targeted at elements of a window that are closed, I guess ;(

@Ms2ger

Ms2ger commented Jul 6, 2016

Copy link
Copy Markdown
Contributor

Fwiw, it's never been clear to me what the JSContext clearing is for.

@jdm

jdm commented Jul 6, 2016

Copy link
Copy Markdown
Member

The goal was to avoid hanging on to JS memory longer than necessary, since clearing it can end up removing the last user of the JS runtime.

@cbrewster

cbrewster commented Jul 6, 2016 •

Copy link
Copy Markdown
Contributor Author

I think I will leave this one as it is, and open a new PR when trying to solve the issue with DOMManipulationTask, so this should be ready for review.

@Ms2ger

Ms2ger commented Jul 7, 2016

Copy link
Copy Markdown
Contributor

I don't think so; the script thread should keep hanging on to the runtime/context.

@Manishearth

Copy link
Copy Markdown
Member

So the wrapper uses Relaxed atomic ordering. Which means that even if the bool is written to from the script thread, it's not necessary that the other thread will see this write in time.

We should either use SeqCst ordering, or Release on the script thread side writes and acquire from the wrapper reads.

Everything else :lgtm:


Reviewed 5 of 6 files at r1, 1 of 5 files at r3, 1 of 1 files at r4, 3 of 3 files at r5.
Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-executed-after-shutdown-child.html, line 9 [r5] (raw file):

  s = document.createElement('script');
  s.type = 'text/javascript';
  s.src = 'script-not-executed-after-shutdown.js?pipe=trickle(d1)';

Perhaps a longer delay would ensure intermittents won't happen on a system experiencing heavy load (like our testing infrastructure at times)?

(Bump the 3000 up as well, of course)


Comments from Reviewable

@cbrewster
cbrewster force-pushed the network_listener_cancellable branch from 411acaf to 5526756 Compare July 8, 2016 15:02
@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Jul 8, 2016
@cbrewster

Copy link
Copy Markdown
Contributor Author

Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-executed-after-shutdown-child.html, line 9 [r5] (raw file):

Previously, Manishearth (Manish Goregaokar) wrote…

Perhaps a longer delay would ensure intermittents won't happen on a system experiencing heavy load (like our testing infrastructure at times)?

(Bump the 3000 up as well, of course)

Done.

tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/script-not-executed-after-shutdown.js, line 1 [r4] (raw file):

Previously, jdm (Josh Matthews) wrote…

This script should call a function in the parent page which would make the test fail. Something like

window.script_executed = t.unreached_func("script executed in removed iframe") in the parent, and in the child: script_executed = parent.script_executed; then invoke script_executed() in this JS file.

Done.

Comments from Reviewable

@Manishearth

Copy link
Copy Markdown
Member

@bors-servo r+


Reviewed 6 of 6 files at r6, 4 of 4 files at r7, 2 of 2 files at r8.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


Comments from Reviewable

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 5526756 has been approved by Manishearth

@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 8, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 5526756 with merge b487a43...

bors-servo pushed a commit that referenced this pull request Jul 8, 2016
…r=Manishearth

Make network listener runnable cancellable

<!-- Please describe your changes on the following line: -->
This keeps scripts from executing after its script thread has been shut down.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] These changes fix (maybe) #12048 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12277)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel

@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 8, 2016
@Manishearth

Copy link
Copy Markdown
Member

@bors-servo retry

  • Seemed to fail compile without any error? Wat.

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 5526756 with merge 12260b2...

bors-servo pushed a commit that referenced this pull request Jul 8, 2016
…r=Manishearth

Make network listener runnable cancellable

<!-- Please describe your changes on the following line: -->
This keeps scripts from executing after its script thread has been shut down.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] These changes fix (maybe) #12048 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12277)
<!-- Reviewable:end -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jul 8, 2016
@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

@bors-servo
bors-servo merged commit 5526756 into servo:master Jul 8, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 8, 2016
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.

6 participants