Skip to content

Commit 59a9da3

Browse files
author
bors-servo
authored
Auto merge of #22474 - csmoe:unregister, r=gterzian
Unregister components while exiting r=@gterzian <!-- Please describe your changes on the following line: --> --- <!-- 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 #22468 (GitHub issue number if applicable) <!-- 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. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22474) <!-- Reviewable:end -->
2 parents 9ca6768 + 5600a1d commit 59a9da3

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

components/background_hang_monitor/background_hang_monitor.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ impl BackgroundHangMonitorClone for HangMonitorRegister {
7272
pub enum MonitoredComponentMsg {
7373
/// Register component for monitoring,
7474
Register(Box<Sampler>, Duration, Duration),
75+
/// Unregister component for monitoring.
76+
Unregister,
7577
/// Notify start of new activity for a given component,
7678
NotifyActivity(HangAnnotation),
7779
/// Notify start of waiting for a new task to come-in for processing.
@@ -119,6 +121,10 @@ impl BackgroundHangMonitor for BackgroundHangMonitorChan {
119121
let msg = MonitoredComponentMsg::NotifyWait;
120122
self.send(msg);
121123
}
124+
fn unregister(&self) {
125+
let msg = MonitoredComponentMsg::Unregister;
126+
self.send(msg);
127+
}
122128
}
123129

124130
struct MonitoredComponent {
@@ -200,6 +206,12 @@ impl BackgroundHangMonitorWorker {
200206
"This component was already registered for monitoring."
201207
);
202208
},
209+
(component_id, MonitoredComponentMsg::Unregister) => {
210+
let _ = self
211+
.monitored_components
212+
.remove_entry(&component_id)
213+
.expect("Received Unregister for an unknown component");
214+
},
203215
(component_id, MonitoredComponentMsg::NotifyActivity(annotation)) => {
204216
let component = self
205217
.monitored_components

components/background_hang_monitor/tests/hang_monitor_tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,30 @@ fn test_hang_monitoring() {
105105
// Still no new alerts because the hang monitor has shut-down already.
106106
assert!(background_hang_monitor_receiver.try_recv().is_err());
107107
}
108+
109+
#[test]
110+
fn test_hang_monitoring_unregister() {
111+
let (background_hang_monitor_ipc_sender, background_hang_monitor_receiver) =
112+
ipc::channel().expect("ipc channel failure");
113+
114+
let background_hang_monitor_register =
115+
HangMonitorRegister::init(background_hang_monitor_ipc_sender.clone());
116+
let background_hang_monitor = background_hang_monitor_register.register_component(
117+
MonitoredComponentId(TEST_PIPELINE_ID, MonitoredComponentType::Script),
118+
Duration::from_millis(10),
119+
Duration::from_millis(1000),
120+
);
121+
122+
// Start an activity.
123+
let hang_annotation = HangAnnotation::Script(ScriptHangAnnotation::AttachLayout);
124+
background_hang_monitor.notify_activity(hang_annotation);
125+
126+
// Unregister the component.
127+
background_hang_monitor.unregister();
128+
129+
// Sleep until the "transient" timeout has been reached.
130+
thread::sleep(Duration::from_millis(10));
131+
132+
// No new alert yet
133+
assert!(background_hang_monitor_receiver.try_recv().is_err());
134+
}

components/layout_thread/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ impl LayoutThread {
926926
self.root_flow.borrow_mut().take();
927927
// Drop the rayon threadpool if present.
928928
let _ = self.parallel_traversal.take();
929+
self.background_hang_monitor.unregister();
929930
}
930931

931932
fn handle_add_stylesheet(&self, stylesheet: &Stylesheet, guard: &SharedRwLockReadGuard) {

components/msg/constellation_msg.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,6 @@ pub trait BackgroundHangMonitor {
469469
fn notify_activity(&self, annotation: HangAnnotation);
470470
/// Notify the start of waiting for a new event to come in.
471471
fn notify_wait(&self);
472+
/// Unregister the component from monitor.
473+
fn unregister(&self);
472474
}

components/script/script_thread.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,8 @@ impl ScriptThread {
23792379
self.handle_exit_pipeline_msg(pipeline_id, DiscardBrowsingContext::Yes);
23802380
}
23812381

2382+
self.background_hang_monitor.unregister();
2383+
23822384
debug!("Exited script thread.");
23832385
}
23842386

0 commit comments

Comments
 (0)