-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Stop runtime on task panic #2002
Comments
Are you able to abort on panic? You could also set a panic_handler that signals the root task ( |
panic hook to signal the root task works. |
Dealing with it in the panic handler is not the best option because maybe I still want to explicitly catch panics in specific scopes, but unexpected panics elsewhere should terminate the whole thing. By default. It's an unpleasant surprise when they don't (see fail-fast). |
Closing in favor of #2699. |
It's not about tests. It's about panics being silently caught everywhere. In production too. Anywhere else in Rust, if there is a panic in the code not explicitly wrapped in It is true that sometimes we need to catch panics to ensure robustness. For example, perhaps we don't want a panic in a request handler to terminate the whole web server program. But that's none of tokio's business! It's web framework's or even web application's business! It is possible to use tokio for something besides web applications, and in those use cases panics definitely shouldn't be silently ignored. Consider reopening. |
In order to deviate from I could buy into a |
What about |
I don't think |
I think inconsistent behavior between
IMO, the main argument for a |
If these tasks are running in the same thread and one of tasks is panic, why the other tasks still working, which makes me more confused. |
@s97712 Panics in spawned tasks are caught, just like they are for spawned threads in std. Tasks spawned with the ordinary |
Any progress on this? |
No, there's currently no way to do this. |
Having a way to tell Tokio to "not catch" panics that occur in its threads seems like a useful feature for me. My use-case: I have my Rust program deployed in Kubernetes. When a panic occurs, I want my program to crash/completely-close, so that Kubernetes can notice the crash and perform its regular handling (eg. restarting the pod, unless it keeps crashing immediately, in which case back off for a while). I looked through the source-code of Tokio, and could not find a way to directly achieve what I wanted. That said, here are some workarounds I have found. Workaround 1Enable Rust's "abort on panic" setting. You can do this by...
B) Or, by adding You can control the granularity of the stack-traces logged to the console by setting the
Workaround 2Add a custom panic handler, which receives the error, prints a backtrace (optionally), and then manually aborts your program (optionally):
I like this approach better because it gives me control of how much of the stacktrace to print (they can be quite long!), as well as whether the panic is of a type that is worth calling The one main drawback is that the backtrace-generation code ( If you want to use the backtrace-generation on Rust stable, you can actually, but it requires a hack where you set this environment variable: You can set that as a global environment variable, or have it set specifically for your cargo-build command. For Docker: Just add a For rust-analyzer (in VSCode): Add this to your project's
|
Related: #4516 |
Version
tokio 0.2.6
Description
I'm indirectly using tokio runtime with basic scheduler (through using actix 0.9.0).
It seems like tokio 0.1 would stop if any task panics, but 0.2.6 catches everything in
task::harness::Harness::poll
and the runtime keeps going.Is there any way to get the old behavior of stopping the runtime?
The text was updated successfully, but these errors were encountered: