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

Add panic handlers again. #2098

Merged
merged 1 commit into from
Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ fn lazy_start(parent_state: ThreadSafeState) -> ResourceId {

let mut runtime = C_RUNTIME.lock().unwrap();
runtime.spawn(lazy(move || {
tokio_util::abort_on_panic();

worker.then(move |result| -> Result<(), ()> {
// Close resource so the future created by
// handle_worker_message_stream exits
Expand Down
17 changes: 16 additions & 1 deletion cli/tokio_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ pub fn run<F>(future: F)
where
F: Future<Item = (), Error = ()> + Send + 'static,
{
abort_on_panic();
// tokio::runtime::current_thread::run(future)
tokio::run(future)
}

// Tokio swallows panics. In order to actually crash when we panic, we
// have to set this custom hook.
// https://github.com/tokio-rs/tokio/issues/495
// https://github.com/tokio-rs/tokio/issues/209
pub fn abort_on_panic() {
std::panic::set_hook(Box::new(|panic_info| {
eprintln!("{}", panic_info.to_string());
std::process::abort();
}));
}

pub fn block_on<F, R, E>(future: F) -> Result<R, E>
where
F: Send + 'static + Future<Item = R, Error = E>,
Expand All @@ -40,7 +52,10 @@ where
let rt = tokio::runtime::Runtime::new().unwrap();
let mut executor = rt.executor();
let mut enter = tokio_executor::enter().expect("Multiple executors at once");
tokio_executor::with_default(&mut executor, &mut enter, move |_enter| f());
tokio_executor::with_default(&mut executor, &mut enter, move |_enter| {
abort_on_panic();
f()
});
}

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ mod tests {
onmessage = function(e) {
console.log("msg from main script", e.data);
if (e.data == "exit") {
close();
delete window.onmessage;
return;
} else {
console.assert(e.data === "hi");
Expand Down