Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUse BHM to terminate hanging JS threads when closing window #27027
Comments
|
We could also use the slow script feature to avoid having to write per-platform code - there's an interrupt callback the JS engine can call which could check a thread-local value to stop running whatever script is currently executing. |
|
https://searchfox.org/mozilla-central/source/dom/ipc/ProcessHangMonitor.cpp#53 From Gecko:
We could do something similar, although I'm wondering how often the callback is triggered when a script is hanging. In the case of trying to close a window it might still appear as a long hang until the next callback. Better than nothing, and could provide some infra for any "slow script" type of workflow. Also cross-platform from the start. Also the constellation doesn't necessarily have to wait until the callback has been triggered, the window could be closed, while leaving any content-process running with a flag set so that when the callback is triggered the Js is stopped... |
|
Ok so that callback isn't called by SM on it's own when a script is running for a long time(I've tried), one needs to call
So we need to pass the See for example https://searchfox.org/mozilla-central/source/dom/ipc/ProcessHangMonitor.cpp#171 |
Ensure clean shutdown of JS threads <!-- Please describe your changes on the following line: --> FIX #26685 FIX #26996 FIX #9672 FIX #27027 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Ensure clean shutdown of JS threads <!-- Please describe your changes on the following line: --> FIX #26685 FIX #26996 FIX #9672 FIX #27027 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Ensure clean shutdown of JS threads <!-- Please describe your changes on the following line: --> FIX #26685 FIX #26996 FIX #9672 FIX #27027 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Ensure clean shutdown of JS threads <!-- Please describe your changes on the following line: --> FIX #26685 FIX #26996 FIX #9672 FIX #27027 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Follow-up on #27016
Since the constellation has a channel available to the BHM(s), when exiting a pipeline fails due to a hanging
ScriptThreadbecause of long-running JS, we could send a message to the BHM(there is either one, or one per content-process), so that it can terminate the thread(or even the whole process), perhaps after having sampled it.I think this is especially important in multiprocess mode, since otherwise JS could simply keep running in a separate process after the main browser process would have exited, and there would not be a way for the user to know about it unless it would inspect running processes in some way(?).
This would have to be done in a per-platform basis, for example for Mac it seems the
thread_terminatemach function could be used.See
components/background_hang_monitor.