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

unhandled_panic(UnhandledPanic::ShutdownRuntime) not working when endless interval loop in tasks #6222

Closed
markus2330 opened this issue Dec 17, 2023 · 1 comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-runtime Module: tokio/runtime

Comments

@markus2330
Copy link

markus2330 commented Dec 17, 2023

Version

Probably only tokio_unstable v1.35.0 relevant for this issue but just in case:
cargo tree:

├── async-ssh2-tokio v0.7.1
│   │   │   ├── tokio v1.35.0
│   │   │   │   └── tokio-macros v2.2.0 (proc-macro)
│   │   │   ├── tokio-stream v0.1.14
│   │   │   │   └── tokio v1.35.0 (*)
│   │   ├── tokio v1.35.0 (*)
│   │   └── tokio-util v0.7.2
│   │       ├── tokio v1.35.0 (*)
│   └── tokio v1.35.0 (*)
│   │   ├── tokio v1.35.0 (*)
│   │   ├── tokio-util v0.7.2 (*)
│   │   ├── tokio v1.35.0 (*)
│   │   ├── tokio v1.35.0 (*)
│   │   └── tokio-native-tls v0.3.1
│   │       └── tokio v1.35.0 (*)
│   ├── tokio v1.35.0 (*)
│   ├── tokio-native-tls v0.3.1 (*)
├── signal-hook-tokio v0.3.1
│   └── tokio v1.35.0 (*)
├── tokio v1.35.0 (*)
└── tokio-util v0.6.10
    └── tokio v1.35.0 (*)

.cargo/config.toml

[build]
rustflags = ["--cfg", "tokio_unstable"]

Platform
The output of uname -a (UNIX):

Linux markusbyte 5.10.0-26-amd64 #1 SMP Debian 5.10.197-1 (2023-09-29) x86_64 GNU/Linux

Description

I tried this code:

use futures::future::join_all;
use std::panic;
use std::time::Duration;
use tokio::runtime::UnhandledPanic;
use tokio::spawn;
use tokio::time::interval;

fn main() {
	tokio::runtime::Builder::new_multi_thread()
		.unhandled_panic(UnhandledPanic::ShutdownRuntime)
		.enable_all()
		.build()
		.unwrap()
		.block_on(async {
			let mut tasks = vec![];
			tasks.push(spawn(async {
				let mut interval = interval(Duration::from_millis(10));
				loop {
					interval.tick().await;
				}
			}));
			tasks.push(spawn(async {
				panic!("boom");
			}));
			join_all(tasks).await;
		});
}

I expected to see this happen:

thread 'tokio-runtime-worker' panicked at src/main.rs:23:17:
boom
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
exit code 101

Instead, this happened:

thread 'tokio-runtime-worker' panicked at src/main.rs:23:17:
boom
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The process is still running and does not quit.

@markus2330 markus2330 added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Dec 17, 2023
@Darksonn Darksonn added the M-runtime Module: tokio/runtime label Dec 22, 2023
@maminrayej
Copy link
Member

This is intended behavior. From the original issue:

When the multi-threaded runtime is selected, these option would have no effect.
Implementing for the multi-threaded runtime would be required before stabilizing
the API but because the implementation is much harder, we should first gather data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-runtime Module: tokio/runtime
Projects
None yet
Development

No branches or pull requests

3 participants