Skip to content

Commit dbf55fa

Browse files
committed
Fix silent error and add custom panic handler again
This is to work around Tokio's panic recovery feautre. Ref tokio-rs/tokio#495 Ref tokio-rs/tokio#209 Ref denoland#1311 Fixes denoland#2097
1 parent 08ab0b0 commit dbf55fa

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

cli/compiler.rs

+7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ fn lazy_start(parent_state: ThreadSafeState) -> ResourceId {
111111

112112
let mut runtime = C_RUNTIME.lock().unwrap();
113113
runtime.spawn(lazy(move || {
114+
// Tokio swallows panics. In order to actually crash when we panic, we
115+
// have to set this custom hook.
116+
std::panic::set_hook(Box::new(|panic_info| {
117+
eprintln!("{}", panic_info.to_string());
118+
std::process::abort();
119+
}));
120+
114121
worker.then(move |result| -> Result<(), ()> {
115122
// Close resource so the future created by
116123
// handle_worker_message_stream exits

cli/main.rs

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ where
7575
}
7676

7777
fn main() {
78+
// Tokio swallows panics. In order to actually crash when we panic, we have
79+
// to set this custom hook.
80+
std::panic::set_hook(Box::new(|panic_info| {
81+
eprintln!("{}", panic_info.to_string());
82+
std::process::abort();
83+
}));
84+
7885
#[cfg(windows)]
7986
ansi_term::enable_ansi_support().ok(); // For Windows 10
8087

cli/tokio_util.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ where
4040
let rt = tokio::runtime::Runtime::new().unwrap();
4141
let mut executor = rt.executor();
4242
let mut enter = tokio_executor::enter().expect("Multiple executors at once");
43-
tokio_executor::with_default(&mut executor, &mut enter, move |_enter| f());
43+
tokio_executor::with_default(&mut executor, &mut enter, move |_enter| {
44+
// Tokio swallows panics. In order to actually crash when we panic, we
45+
// have to set this custom hook.
46+
std::panic::set_hook(Box::new(|panic_info| {
47+
eprintln!("{}", panic_info.to_string());
48+
std::process::abort();
49+
}));
50+
f()
51+
});
4452
}
4553

4654
#[derive(Debug)]

cli/worker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ mod tests {
324324
onmessage = function(e) {
325325
console.log("msg from main script", e.data);
326326
if (e.data == "exit") {
327-
close();
327+
delete window.onmessage;
328328
return;
329329
} else {
330330
console.assert(e.data === "hi");

0 commit comments

Comments
 (0)