Skip to content
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

Make network listener runnable cancellable #12277

Merged
merged 3 commits into from Jul 8, 2016

Conversation

@cbrewster
Copy link
Member

cbrewster commented Jul 5, 2016

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


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix (maybe) #12048 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Jul 5, 2016

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
Copy link

highfive commented Jul 5, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@jdm
Copy link
Member

jdm commented Jul 5, 2016

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
Copy link
Member Author

cbrewster commented Jul 6, 2016

@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 cbrewster:network_listener_cancellable branch 2 times, most recently from 632324b to 2246f58 Jul 6, 2016
@cbrewster
Copy link
Member Author

cbrewster commented Jul 6, 2016

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

@cbrewster cbrewster force-pushed the cbrewster:network_listener_cancellable branch from 2246f58 to 0cd7688 Jul 6, 2016
@cbrewster
Copy link
Member Author

cbrewster commented Jul 6, 2016

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

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

Trying commit 0cd7688 with merge a4fb625...

bors-servo added 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
Copy link
Member

jdm commented Jul 6, 2016

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

@cbrewster
Copy link
Member Author

cbrewster commented Jul 6, 2016

@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
Copy link
Member

jdm commented Jul 6, 2016

True!

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

This comment has been minimized.

@jdm

jdm Jul 6, 2016

Member

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 cbrewster:network_listener_cancellable branch from 0cd7688 to 411acaf Jul 6, 2016
@cbrewster
Copy link
Member Author

cbrewster commented Jul 6, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

Trying commit 411acaf with merge 7b83970...

bors-servo added 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
Member Author

cbrewster commented Jul 6, 2016

Well this does not seem to fix the intermittent :(

@bors-servo
Copy link
Contributor

bors-servo commented Jul 6, 2016

💔 Test failed - linux-rel

@jdm
Copy link
Member

jdm commented Jul 6, 2016

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

@cbrewster
Copy link
Member Author

cbrewster commented Jul 6, 2016

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

@jdm
Copy link
Member

jdm commented Jul 6, 2016

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

@jdm
Copy link
Member

jdm commented Jul 6, 2016

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
Copy link
Member

jdm commented Jul 6, 2016

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
Copy link
Contributor

Ms2ger commented Jul 6, 2016

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

@jdm
Copy link
Member

jdm commented Jul 6, 2016

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
Copy link
Member Author

cbrewster commented Jul 6, 2016

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
Copy link
Contributor

Ms2ger commented Jul 7, 2016

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

@Manishearth
Copy link
Member

Manishearth commented Jul 8, 2016

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 cbrewster:network_listener_cancellable branch from 411acaf to 5526756 Jul 8, 2016
@highfive highfive removed the S-tests-failed label Jul 8, 2016
@cbrewster
Copy link
Member Author

cbrewster commented Jul 8, 2016

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
Member

Manishearth commented Jul 8, 2016

@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
Contributor

bors-servo commented Jul 8, 2016

📌 Commit 5526756 has been approved by Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented Jul 8, 2016

Testing commit 5526756 with merge b487a43...

bors-servo added 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
Contributor

bors-servo commented Jul 8, 2016

💔 Test failed - linux-rel

@Manishearth
Copy link
Member

Manishearth commented Jul 8, 2016

@bors-servo retry

  • Seemed to fail compile without any error? Wat.
@bors-servo
Copy link
Contributor

bors-servo commented Jul 8, 2016

Testing commit 5526756 with merge 12260b2...

bors-servo added 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
Contributor

bors-servo commented Jul 8, 2016

@bors-servo bors-servo merged commit 5526756 into servo:master Jul 8, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.