diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-14 19:55:17 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-14 19:55:17 +0530 |
commit | 2b910678db8b461dc50919832044bd95cdecb53e (patch) | |
tree | 54a935ee9f1b6dbdcf3f85904c7b4198a6212335 | |
parent | 3368565b3c6c76e5ce2d170d5c5cfb2f52a56956 (diff) | |
parent | 8c0fa01884bfb4dcf7d591aa06f48f78f7970766 (diff) | |
download | servo-2b910678db8b461dc50919832044bd95cdecb53e.tar.gz servo-2b910678db8b461dc50919832044bd95cdecb53e.zip |
Auto merge of #10587 - asajeffrey:add-failure-panic-message, r=Manishearth
Added panic message to failures.
Added the panic message to failures. This is a step towards #10334, since it gives us access to the panic error message when we fire a `mozbrowsererror` event. The remaining steps are also to record the backtrace, and to report the failure in the event.
<!-- 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/10587)
<!-- Reviewable:end -->
-rw-r--r-- | components/compositing/constellation.rs | 35 | ||||
-rw-r--r-- | components/compositing/pipeline.rs | 9 | ||||
-rw-r--r-- | components/gfx/paint_thread.rs | 2 | ||||
-rw-r--r-- | components/gfx_traits/lib.rs | 6 | ||||
-rw-r--r-- | components/layout/layout_thread.rs | 2 | ||||
-rw-r--r-- | components/msg/constellation_msg.rs | 20 | ||||
-rw-r--r-- | components/script/script_thread.rs | 4 | ||||
-rw-r--r-- | components/script_traits/script_msg.rs | 12 | ||||
-rw-r--r-- | components/util/thread.rs | 35 |
9 files changed, 88 insertions, 37 deletions
diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 97d3fca36c2..e824340c1a4 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -653,9 +653,9 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> // Messages from script - Request::Script(FromScriptMsg::Failure(Failure { pipeline_id, parent_info })) => { - debug!("handling script failure message from pipeline {:?}, {:?}", pipeline_id, parent_info); - self.handle_failure_msg(pipeline_id, parent_info); + Request::Script(FromScriptMsg::Failure(failure)) => { + debug!("handling script failure message from pipeline {:?}", failure); + self.handle_failure_msg(failure); } Request::Script(FromScriptMsg::ScriptLoadedURLInIFrame(load_info)) => { debug!("constellation got iframe URL load message {:?} {:?} {:?}", @@ -786,9 +786,9 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> Request::Layout(FromLayoutMsg::ChangeRunningAnimationsState(pipeline_id, animation_state)) => { self.handle_change_running_animations_state(pipeline_id, animation_state) } - Request::Layout(FromLayoutMsg::Failure(Failure { pipeline_id, parent_info })) => { - debug!("handling paint failure message from pipeline {:?}, {:?}", pipeline_id, parent_info); - self.handle_failure_msg(pipeline_id, parent_info); + Request::Layout(FromLayoutMsg::Failure(failure)) => { + debug!("handling paint failure message from pipeline {:?}", failure); + self.handle_failure_msg(failure); } Request::Layout(FromLayoutMsg::SetCursor(cursor)) => { self.handle_set_cursor_msg(cursor) @@ -803,9 +803,9 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> // Notification that painting has finished and is requesting permission to paint. - Request::Paint(FromPaintMsg::Failure(Failure { pipeline_id, parent_info })) => { - debug!("handling paint failure message from pipeline {:?}, {:?}", pipeline_id, parent_info); - self.handle_failure_msg(pipeline_id, parent_info); + Request::Paint(FromPaintMsg::Failure(failure)) => { + debug!("handling paint failure message from pipeline {:?}", failure); + self.handle_failure_msg(failure); } } @@ -835,12 +835,11 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> Some(pipeline) => pipeline.parent_info, }; // Treat send error the same as receiving a failure message - self.handle_failure_msg(pipeline_id, parent_info); + let failure = Failure::new(pipeline_id, parent_info); + self.handle_failure_msg(failure); } - fn handle_failure_msg(&mut self, - pipeline_id: PipelineId, - parent_info: Option<(PipelineId, SubpageId)>) { + fn handle_failure_msg(&mut self, failure: Failure) { if opts::get().hard_fail { // It's quite difficult to make Servo exit cleanly if some threads have failed. // Hard fail exists for test runners so we crash and that's good enough. @@ -850,12 +849,12 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> process::exit(1); } - let window_size = self.pipelines.get(&pipeline_id).and_then(|pipeline| pipeline.size); + let window_size = self.pipelines.get(&failure.pipeline_id).and_then(|pipeline| pipeline.size); - self.close_pipeline(pipeline_id, ExitPipelineMode::Force); + self.close_pipeline(failure.pipeline_id, ExitPipelineMode::Force); while let Some(pending_pipeline_id) = self.pending_frames.iter().find(|pending| { - pending.old_pipeline_id == Some(pipeline_id) + pending.old_pipeline_id == Some(failure.pipeline_id) }).map(|frame| frame.new_pipeline_id) { warn!("removing pending frame change for failed pipeline"); self.close_pipeline(pending_pipeline_id, ExitPipelineMode::Force); @@ -865,12 +864,12 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF> let new_pipeline_id = PipelineId::new(); self.new_pipeline(new_pipeline_id, - parent_info, + failure.parent_info, window_size, None, LoadData::new(Url::parse("about:failure").unwrap())); - self.push_pending_frame(new_pipeline_id, Some(pipeline_id)); + self.push_pending_frame(new_pipeline_id, Some(failure.pipeline_id)); } diff --git a/components/compositing/pipeline.rs b/components/compositing/pipeline.rs index 3a45a486b8a..3de923ba858 100644 --- a/components/compositing/pipeline.rs +++ b/components/compositing/pipeline.rs @@ -140,10 +140,7 @@ impl Pipeline { .expect("Pipeline script to compositor chan"); let mut pipeline_port = Some(pipeline_port); - let failure = Failure { - pipeline_id: state.id, - parent_info: state.parent_info, - }; + let failure = Failure::new(state.id, state.parent_info); let window_size = state.window_size.map(|size| { WindowSizeData { @@ -182,7 +179,7 @@ impl Pipeline { subpage_id: subpage_id, load_data: state.load_data.clone(), paint_chan: layout_to_paint_chan.clone().to_opaque(), - failure: failure, + failure: failure.clone(), pipeline_port: mem::replace(&mut pipeline_port, None) .expect("script_pipeline != None but pipeline_port == None"), layout_shutdown_chan: layout_shutdown_chan.clone(), @@ -230,7 +227,7 @@ impl Pipeline { layout_to_constellation_chan: state.layout_to_constellation_chan, script_chan: script_chan, load_data: state.load_data.clone(), - failure: failure, + failure: failure.clone(), script_port: script_port, opts: (*opts::get()).clone(), prefs: prefs::get_cloned(), diff --git a/components/gfx/paint_thread.rs b/components/gfx/paint_thread.rs index 50afd79bd58..2de6b0c4628 100644 --- a/components/gfx/paint_thread.rs +++ b/components/gfx/paint_thread.rs @@ -441,7 +441,7 @@ impl<C> PaintThread<C> where C: PaintListener + Send + 'static { debug!("paint_thread: shutdown_chan send"); shutdown_chan.send(()).unwrap(); - }, ConstellationMsg::Failure(failure_msg), c); + }, failure_msg, c); } #[allow(unsafe_code)] diff --git a/components/gfx_traits/lib.rs b/components/gfx_traits/lib.rs index 6f5abcb1963..ed78a9c74b0 100644 --- a/components/gfx_traits/lib.rs +++ b/components/gfx_traits/lib.rs @@ -34,6 +34,12 @@ pub enum PaintMsg { Failure(Failure), } +impl From<Failure> for PaintMsg { + fn from(failure: Failure) -> PaintMsg { + PaintMsg::Failure(failure) + } +} + #[derive(Clone, Copy, Debug, PartialEq)] pub enum LayerKind { NoTransform, diff --git a/components/layout/layout_thread.rs b/components/layout/layout_thread.rs index f6f88a0f29b..9c184880ecd 100644 --- a/components/layout/layout_thread.rs +++ b/components/layout/layout_thread.rs @@ -286,7 +286,7 @@ impl LayoutThreadFactory for LayoutThread { } let _ = shutdown_chan.send(()); let _ = content_process_shutdown_chan.send(()); - }, ConstellationMsg::Failure(failure_msg), con_chan); + }, failure_msg, con_chan); } } diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 8c1c02feaf0..c9b8d0acd88 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -16,6 +16,7 @@ use std::cell::Cell; use std::fmt; use url::Url; use util::geometry::{PagePx, ViewportPx}; +use util::thread::AddFailureDetails; use webdriver_msg::{LoadStatus, WebDriverScriptCommand}; use webrender_traits; @@ -36,10 +37,27 @@ impl<T: Serialize + Deserialize> Clone for ConstellationChan<T> { } // We pass this info to various threads, so it lives in a separate, cloneable struct. -#[derive(Clone, Copy, Deserialize, Serialize)] +#[derive(Clone, Deserialize, Serialize, Debug)] pub struct Failure { pub pipeline_id: PipelineId, pub parent_info: Option<(PipelineId, SubpageId)>, + pub panic_message: Option<String>, +} + +impl Failure { + pub fn new(pipeline_id: PipelineId, parent_info: Option<(PipelineId, SubpageId)>) -> Failure { + Failure { + pipeline_id: pipeline_id, + parent_info: parent_info, + panic_message: None, + } + } +} + +impl AddFailureDetails for Failure { + fn add_panic_message(&mut self, message: String) { + self.panic_message = Some(message); + } } #[derive(Copy, Clone, Deserialize, Serialize, HeapSizeOf)] diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 7029f34e753..5f2ecd095ba 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -445,7 +445,7 @@ impl ScriptThreadFactory for ScriptThread { let ConstellationChan(const_chan) = state.constellation_chan.clone(); let (script_chan, script_port) = channel(); let layout_chan = LayoutChan(layout_chan.sender()); - let failure_info = state.failure_info; + let failure_info = state.failure_info.clone(); thread::spawn_named_with_send_on_failure(format!("ScriptThread {:?}", state.id), thread_state::SCRIPT, move || { @@ -481,7 +481,7 @@ impl ScriptThreadFactory for ScriptThread { // This must always be the very last operation performed before the thread completes failsafe.neuter(); - }, ConstellationMsg::Failure(failure_info), const_chan); + }, failure_info, const_chan); } } diff --git a/components/script_traits/script_msg.rs b/components/script_traits/script_msg.rs index 10bb4864c4b..23920d150d1 100644 --- a/components/script_traits/script_msg.rs +++ b/components/script_traits/script_msg.rs @@ -32,6 +32,12 @@ pub enum LayoutMsg { ViewportConstrained(PipelineId, ViewportConstraints), } +impl From<Failure> for LayoutMsg { + fn from(failure: Failure) -> LayoutMsg { + LayoutMsg::Failure(failure) + } +} + /// Messages from the script to the constellation. #[derive(Deserialize, Serialize)] pub enum ScriptMsg { @@ -86,3 +92,9 @@ pub enum ScriptMsg { /// Update the pipeline Url, which can change after redirections. SetFinalUrl(PipelineId, Url), } + +impl From<Failure> for ScriptMsg { + fn from(failure: Failure) -> ScriptMsg { + ScriptMsg::Failure(failure) + } +} diff --git a/components/util/thread.rs b/components/util/thread.rs index 9451d0a434f..b8fba1aa773 100644 --- a/components/util/thread.rs +++ b/components/util/thread.rs @@ -5,6 +5,7 @@ use ipc_channel::ipc::IpcSender; use opts; use serde::Serialize; +use std::any::Any; use std::borrow::ToOwned; use std::io::{Write, stderr}; use std::panic::{PanicInfo, take_hook, set_hook}; @@ -13,6 +14,8 @@ use std::thread; use std::thread::Builder; use thread_state; +pub type PanicReason = Option<String>; + pub fn spawn_named<F>(name: String, f: F) where F: FnOnce() + Send + 'static { @@ -52,6 +55,17 @@ pub fn spawn_named<F>(name: String, f: F) builder.spawn(f_with_hook).unwrap(); } +pub trait AddFailureDetails { + fn add_panic_message(&mut self, message: String); + fn add_panic_object(&mut self, object: Box<Any>) { + if let Some(message) = object.downcast_ref::<String>() { + self.add_panic_message(message.to_owned()); + } else if let Some(&message) = object.downcast_ref::<&'static str>() { + self.add_panic_message(message.to_owned()); + } + } +} + /// An abstraction over `Sender<T>` and `IpcSender<T>`, for use in /// `spawn_named_with_send_on_failure`. pub trait SendOnFailure { @@ -62,14 +76,16 @@ pub trait SendOnFailure { impl<T> SendOnFailure for Sender<T> where T: Send + 'static { type Value = T; fn send_on_failure(&mut self, value: T) { - self.send(value).unwrap(); + // Discard any errors to avoid double-panic + let _ = self.send(value); } } impl<T> SendOnFailure for IpcSender<T> where T: Send + Serialize + 'static { type Value = T; fn send_on_failure(&mut self, value: T) { - self.send(value).unwrap(); + // Discard any errors to avoid double-panic + let _ = self.send(value); } } @@ -77,11 +93,13 @@ impl<T> SendOnFailure for IpcSender<T> where T: Send + Serialize + 'static { pub fn spawn_named_with_send_on_failure<F, T, S>(name: String, state: thread_state::ThreadState, f: F, - msg: T, + mut msg: T, mut dest: S) - where F: FnOnce() + Send + 'static, - T: Send + 'static, - S: Send + SendOnFailure<Value=T> + 'static { + where F: FnOnce() + Send + 'static, + T: Send + AddFailureDetails + 'static, + S: Send + SendOnFailure + 'static, + S::Value: From<T>, +{ let future_handle = thread::Builder::new().name(name.to_owned()).spawn(move || { thread_state::initialize(state); f() @@ -91,9 +109,10 @@ pub fn spawn_named_with_send_on_failure<F, T, S>(name: String, Builder::new().name(watcher_name).spawn(move || { match future_handle.join() { Ok(()) => (), - Err(..) => { + Err(err) => { debug!("{} failed, notifying constellation", name); - dest.send_on_failure(msg); + msg.add_panic_object(err); + dest.send_on_failure(S::Value::from(msg)); } } }).unwrap(); |