Skip to content

Commit

Permalink
constellation: don't make shutdown depend on having exited all pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
gterzian committed Jun 22, 2020
1 parent 0b61cfc commit afed14c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
14 changes: 10 additions & 4 deletions components/config/prefs.rs
Expand Up @@ -123,6 +123,16 @@ mod gen {
},
},
},
constellation: {
pipeline_exit: {
timeout_ms: i64,
sampling_duration_ms: i64
},
session_history: {
#[serde(rename = "session-history.max-length")]
max_length: i64,
},
},
dom: {
webgpu: {
enabled: bool,
Expand Down Expand Up @@ -454,10 +464,6 @@ mod gen {
sniff: bool,
}
},
session_history: {
#[serde(rename = "session-history.max-length")]
max_length: i64,
},
shell: {
homepage: String,
keep_screen_on: {
Expand Down
50 changes: 48 additions & 2 deletions components/constellation/constellation.rs
Expand Up @@ -174,6 +174,7 @@ use std::process;
use std::rc::{Rc, Weak};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
use style_traits::viewport::ViewportConstraints;
use style_traits::CSSPixel;
use webgpu::{self, WebGPU, WebGPURequest};
Expand Down Expand Up @@ -954,15 +955,60 @@ where

/// The main event loop for the constellation.
fn run(&mut self) {
while !self.shutting_down || !self.pipelines.is_empty() {
while !self.shutting_down {
// Randomly close a pipeline if --random-pipeline-closure-probability is set
// This is for testing the hardening of the constellation.
self.maybe_close_random_pipeline();
self.handle_request();
}

// Try to cleanly exit all pipelines, until a timeout hits.
let pipeline_exit_timeout = after(Duration::from_millis(pref!(
constellation.pipeline_exit.timeout_ms
) as u64));
while !self.pipelines.is_empty() {
select! {
recv(self.script_receiver) -> msg => {
match msg.expect("Unexpected script channel panic in constellation") {
Ok((source_pipeline_id, FromScriptMsg::PipelineExited)) => {
self.handle_pipeline_exited(source_pipeline_id);
},
_ => continue,
}
}
recv(pipeline_exit_timeout) -> _ => {
if !self.pipelines.is_empty() {
self.sample_all_hanging_pipelines();
}
break;
},
}
}
self.handle_shutdown();
}

/// Sample all pipelines that have failed to exit cleanly.
fn sample_all_hanging_pipelines(&self) {
warn!("Failed to exit a number of pipelines {:?}", self.pipelines.len());
if opts::get().background_hang_monitor {
println!("Sampling hanging pipelines: {:?}", self.pipelines.keys());
let sampling_duration = Duration::from_millis(
pref!(constellation.pipeline_exit.sampling_duration_ms
) as u64);
for chan in &self.sampling_profiler_control {
let _ = chan.send(SamplerControlMsg::Enable(sampling_duration, sampling_duration));
thread::sleep(sampling_duration);
let _ = chan.send(SamplerControlMsg::Disable);
while let Ok(msg) = self.background_hang_monitor_receiver.as_ref().unwrap().recv().unwrap() {
if let HangMonitorAlert::Profile(bytes) = msg {
println!("Pipeline is hanging on: {:?}", String::from_utf8_lossy(&bytes));
break;
}
}
}
}
}

/// Generate a new pipeline id namespace.
fn next_pipeline_namespace_id(&mut self) -> PipelineNamespaceId {
let namespace_id = self.next_pipeline_namespace_id;
Expand Down Expand Up @@ -4828,7 +4874,7 @@ where
let pipelines_to_evict = {
let session_history = self.get_joint_session_history(top_level_browsing_context_id);

let history_length = pref!(session_history.max_length) as usize;
let history_length = pref!(constellation.session_history.max_length) as usize;

// The past is stored with older entries at the front.
// We reverse the iter so that newer entries are at the front and then
Expand Down
4 changes: 3 additions & 1 deletion resources/prefs.json
@@ -1,4 +1,7 @@
{
"constellation.pipeline_exit.timeout_ms": 200,
"constellation.pipeline_exit.sampling_duration_ms": 200,
"constellation.session-history.max-length": 20,
"dom.bluetooth.enabled": false,
"dom.bluetooth.testing.enabled": false,
"dom.canvas-text.enabled": true,
Expand Down Expand Up @@ -99,7 +102,6 @@
"network.enforce_tls.onion": false,
"network.http-cache.disabled": false,
"network.mime.sniff": false,
"session-history.max-length": 20,
"shell.homepage": "https://servo.org",
"shell.keep_screen_on.enabled": false,
"shell.native-orientation": "both",
Expand Down

0 comments on commit afed14c

Please sign in to comment.