From d51f16855bce90c3c73ae199c7d6bdb340297e99 Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Wed, 20 Mar 2024 12:18:09 +0330 Subject: [PATCH] runtime: panic if `unhandled_panic` is enabled when not supported (#6410) --- tokio/src/runtime/builder.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tokio/src/runtime/builder.rs b/tokio/src/runtime/builder.rs index e20a3c495..82d359691 100644 --- a/tokio/src/runtime/builder.rs +++ b/tokio/src/runtime/builder.rs @@ -824,6 +824,10 @@ impl Builder { /// will immediately terminate and further calls to /// [`Runtime::block_on`] will panic. /// + /// # Panics + /// This method panics if called with [`UnhandledPanic::ShutdownRuntime`] + /// on a runtime other than the current thread runtime. + /// /// # Unstable /// /// This option is currently unstable and its implementation is @@ -861,6 +865,10 @@ impl Builder { /// /// [`JoinHandle`]: struct@crate::task::JoinHandle pub fn unhandled_panic(&mut self, behavior: UnhandledPanic) -> &mut Self { + if !matches!(self.kind, Kind::CurrentThread) && matches!(behavior, UnhandledPanic::ShutdownRuntime) { + panic!("UnhandledPanic::ShutdownRuntime is only supported in current thread runtime"); + } + self.unhandled_panic = behavior; self }