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

runtime: prevent using unhandled_panic option on multi-thread runtime #6410

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions tokio/src/runtime/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down