From c97a68392422968ecf798465715a25fd61afa110 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 23 Apr 2019 10:22:14 -0400 Subject: [PATCH 1/4] Forward panic_handler to tokio::runtime::Builder --- tokio/src/runtime/threadpool/builder.rs | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tokio/src/runtime/threadpool/builder.rs b/tokio/src/runtime/threadpool/builder.rs index d32251da031..b8ded268708 100644 --- a/tokio/src/runtime/threadpool/builder.rs +++ b/tokio/src/runtime/threadpool/builder.rs @@ -101,6 +101,36 @@ impl Builder { self } + /// Sets a callback to be triggered when a panic during a future bubbles up + /// to Tokio. By default Tokio catches these panics, and they will be + /// ignored. The parameter passed to this callback is the same error value + /// returned from std::panic::catch_unwind(). To abort the process on + /// panics, use std::panic::resume_unwind() in this callback as shown + /// below. + /// + /// # Examples + /// + /// ``` + /// # extern crate tokio; + /// # extern crate futures; + /// # use tokio::runtime; + /// + /// # pub fn main() { + /// let mut rt = runtime::Builder::new() + /// .panic_handler(|err| std::panic::resume_unwind(err)) + /// .build() + /// .unwrap(); + /// # } + /// ``` + pub fn panic_handler(&mut self, f: F) -> &mut Self + where + F: Fn(Box) + Send + Sync + 'static, + { + self.threadpool_builder.panic_handler(f) + self + } + + /// Set the maximum number of worker threads for the `Runtime`'s thread pool. /// /// This must be a number between 1 and 32,768 though it is advised to keep From 6104ae8752f8a63218ae8876453846528d6aea94 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 23 Apr 2019 10:31:50 -0400 Subject: [PATCH 2/4] fix --- tokio/src/runtime/threadpool/builder.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tokio/src/runtime/threadpool/builder.rs b/tokio/src/runtime/threadpool/builder.rs index b8ded268708..533843b623c 100644 --- a/tokio/src/runtime/threadpool/builder.rs +++ b/tokio/src/runtime/threadpool/builder.rs @@ -5,6 +5,7 @@ use reactor::Reactor; use std::io; use std::sync::Mutex; use std::time::Duration; +use std::any::Any; use num_cpus; use tokio_reactor; @@ -126,7 +127,7 @@ impl Builder { where F: Fn(Box) + Send + Sync + 'static, { - self.threadpool_builder.panic_handler(f) + self.threadpool_builder.panic_handler(f); self } From cbb3c3dcd3f1d72c8f2c5825b10ca5b5b16f3b8a Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Tue, 23 Apr 2019 13:38:02 -0400 Subject: [PATCH 3/4] Update tokio/src/runtime/threadpool/builder.rs Co-Authored-By: ry --- tokio/src/runtime/threadpool/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio/src/runtime/threadpool/builder.rs b/tokio/src/runtime/threadpool/builder.rs index 533843b623c..88adc2a32a1 100644 --- a/tokio/src/runtime/threadpool/builder.rs +++ b/tokio/src/runtime/threadpool/builder.rs @@ -105,7 +105,7 @@ impl Builder { /// Sets a callback to be triggered when a panic during a future bubbles up /// to Tokio. By default Tokio catches these panics, and they will be /// ignored. The parameter passed to this callback is the same error value - /// returned from std::panic::catch_unwind(). To abort the process on + /// returned from `std::panic::catch_unwind()`. To abort the process on /// panics, use std::panic::resume_unwind() in this callback as shown /// below. /// From e72886a9b7772d13604001f65fcd28896461feea Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 23 Apr 2019 13:41:20 -0400 Subject: [PATCH 4/4] adjust docs --- tokio/src/runtime/threadpool/builder.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tokio/src/runtime/threadpool/builder.rs b/tokio/src/runtime/threadpool/builder.rs index 88adc2a32a1..030b3ca2060 100644 --- a/tokio/src/runtime/threadpool/builder.rs +++ b/tokio/src/runtime/threadpool/builder.rs @@ -102,12 +102,13 @@ impl Builder { self } - /// Sets a callback to be triggered when a panic during a future bubbles up - /// to Tokio. By default Tokio catches these panics, and they will be - /// ignored. The parameter passed to this callback is the same error value - /// returned from `std::panic::catch_unwind()`. To abort the process on - /// panics, use std::panic::resume_unwind() in this callback as shown - /// below. + /// Sets a callback to handle panics in futures. + /// + /// The callback is triggered when a panic during a future bubbles up to + /// Tokio. By default Tokio catches these panics, and they will be ignored. + /// The parameter passed to this callback is the same error value returned + /// from `std::panic::catch_unwind()`. To abort the process on panics, use + /// `std::panic::resume_unwind()` in this callback as shown below. /// /// # Examples ///