-
-
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
rt: provide options to configure unhandled panic behavior #4516
Comments
Allows the user to configure the runtime's behavior when a spawned task panics. Currently, the panic is propagated to the JoinHandle and the runtime resumes. This patch lets the user set the runtime to shutdown on unhandled panic. So far, this is only implemented for the current-thread runtime. Refs: #4516
Allows the user to configure the runtime's behavior when a spawned task panics. Currently, the panic is propagated to the JoinHandle and the runtime resumes. This patch lets the user set the runtime to shutdown on unhandled panic. So far, this is only implemented for the current-thread runtime. Refs: #4516
Allows the user to configure the runtime's behavior when a spawned task panics. Currently, the panic is propagated to the JoinHandle and the runtime resumes. This patch lets the user set the runtime to shutdown on unhandled panic. So far, this is only implemented for the current-thread runtime. Refs: #4516
Thank you for working on the issue, it sounds great and I would like to use it. For me, ShutdownRuntime with tokio unstable 1.35.0 does not work once I build the runtime with Shutdown on Panic worksE.g. with:
The process gets terminated on a panic. Shutdown on Panic FailsBut once I use Unfortunately, I couldn't get Should I create an issue? Or is it obvious that it currently won't work? (As the feature is not implemented fully.) |
Feel free to create an issue. |
Thx for the invitation 🚀, I was able to create a minimal reproducible example: #6222 Would be great to see it fixed, soon 💞 |
As testing-related issues were closed in favor of this one, I'm posting my question here: For tests purposes, is there any known (even very hacky) way to detect presence of panicked tasks on a multi-threaded runtime? (Without overwriting the global panic hook.) Maybe it would be relatively easy to extend |
We have the |
Well, that's the topic of this very issue :). AFAIR it is still not implemented for the multi-threaded runtime:
|
Fair enough. We do not support that right now. |
Currently, all panics on tasks are caught and exposed to the user via
Joinhandle
. However, it is somewhat uncommon to use theJoinHandle
.Background tasks are spawned and may silently fail resulting in the rest of the
application to hang. Also, in tests, a background task that panics can result in
the test hanging indefinitely, making debugging annoying.
That said, the current behavior is the correct default. Even if it weren't,
changing it now would be too late. A task boundary is a logical boundary to
separate failure. When implementing a sever, it is not desirable to have an
uncommon bug in one request handler to take down the entire process.
So, because different scenarios merit different behaviors, a runtime
configuration option could provide the user with the ability to pick the
behavior best suited for their case.
There are a few ways panics could be handled:
JoinHandle
and ignore otherwise (what happens today).Joinhandle
but if theJoinHandle
drops (ignores the result)then shutdown the runtime.
strategies to take.
So, to expose the different options to the user:
Runtime shutdown
What does it mean to "shutdown the runtime" on unhandled panic. First, the
current shutdown behavior is executed. All in-flight tasks are forcibly aborted
and runtime resources are disabled. The next question is how to expose the
unhandled panic.
If the user enables "shutdown runtime on unhandled panic" and a panic does get
through, it seems likely that this is a bug. The
Runtime
methods in questionare:
spawn
block_on
spawn
could maintain the current behavior when called after a runtime hasshutdown: immediately drop the task and complete the
JoinHandle
with an error.The
block_on
method does not return result. The only option I see is for it topanic when the runtime has seen an unhandled panic.
To compensate, we could add methods on
Runtime
to query the runtime state,e.g.
Runtime::status() -> Running | Shutdown | UnhandledPanic | ...
Initial implementation
As an initial step to get the feature going. I suggest implementing an MVP
version of the feature as an unstable API and only for the
current_thread
runtime. This would let us explore the space more and try things out. The
initial implementation could also start by only letting the user pick between
the current behavior and
ShutdownRuntime
. So: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.
Open questions
block_on
or theJoinHandle
(ref: rt: provide options to configure unhandled panic behavior #4516).LocalSet
andJoinSet
work. Should they track their own settings or inherit from the runtime? Should there be aLocalSet::builder()
?Known issues
The text was updated successfully, but these errors were encountered: