Skip to content

Commit d51f168

Browse files
authored
runtime: panic if unhandled_panic is enabled when not supported (#6410)
1 parent 5baa8d5 commit d51f168

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tokio/src/runtime/builder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,10 @@ impl Builder {
824824
/// will immediately terminate and further calls to
825825
/// [`Runtime::block_on`] will panic.
826826
///
827+
/// # Panics
828+
/// This method panics if called with [`UnhandledPanic::ShutdownRuntime`]
829+
/// on a runtime other than the current thread runtime.
830+
///
827831
/// # Unstable
828832
///
829833
/// This option is currently unstable and its implementation is
@@ -861,6 +865,10 @@ impl Builder {
861865
///
862866
/// [`JoinHandle`]: struct@crate::task::JoinHandle
863867
pub fn unhandled_panic(&mut self, behavior: UnhandledPanic) -> &mut Self {
868+
if !matches!(self.kind, Kind::CurrentThread) && matches!(behavior, UnhandledPanic::ShutdownRuntime) {
869+
panic!("UnhandledPanic::ShutdownRuntime is only supported in current thread runtime");
870+
}
871+
864872
self.unhandled_panic = behavior;
865873
self
866874
}

0 commit comments

Comments
 (0)