-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 (threadpool) does not shutdown when thread panics #209
Comments
Thanks! This is definitely an omission. |
@carllerche In this case one could expect futures-cpupool simply uses "CpuFuture" as a "backchannel" (which we do not have for tokio::run) for this, So some ideas that could work from my point of view so far:
|
ah, sorry... i'm looking into it right now. It seems to be exposing some other limitations. |
Currently, the runtime does not shutdown if the runtime handle is dropped. This can happen during a panic or when the value is simply dropped. This patch forces the runtime to shutdown if it is not explicitly shutdown. Fixes tokio-rs#209
I opened #214. This shuts down the worker threads, but many not result in all spawned futures to be dropped. These futures aren't leaked per se as they are tied to their notification handles, but this is probably not what is intended. |
Currently, the runtime does not shutdown if the runtime handle is dropped. This can happen during a panic or when the value is simply dropped. This patch forces the runtime to shutdown if it is not explicitly shutdown. Fixes tokio-rs#209
@carllerche |
Ah right, i read it wrong... |
If a future panics from within the context of a thread pool, the pool should not be impacted. To do this, polling the future is wrapped with a catch_unwind. Extra care is taken to ensure that `thread::panicking()` is set from within the future's drop handle. Fixes tokio-rs#209
I pushed #216 which wraps the task with a If the caller wishes to know if the future panicked, that should be handled by the caller. |
@carllerche That sounds reasonable and works. |
If a future panics from within the context of a thread pool, the pool should not be impacted. To do this, polling the future is wrapped with a catch_unwind. Extra care is taken to ensure that `thread::panicking()` is set from within the future's drop handle. Fixes #209
Currently, the runtime does not shutdown if the runtime handle is dropped. This can happen during a panic or when the value is simply dropped. This patch forces the runtime to shutdown if it is not explicitly shutdown. Fixes #209
What would be the best way of handling this? The following is the best/first thing I could come up with :/ pub fn run_no_panic_catch<F>(fut: F)
where
F: Future<Item = (), Error = ()> + Send + ::std::panic::UnwindSafe + 'static,
{
use std::sync::{Arc, Mutex};
let error_result = Arc::new(Mutex::new(None));
{
let error_result = error_result.clone();
tokio::run(
fut.catch_unwind()
.map_err(move |err| {
*error_result.lock().unwrap() = Some(err);
})
.and_then(|result| result),
);
}
if let Some(err) = Arc::try_unwrap(error_result).unwrap().into_inner().unwrap() {
panic!(err)
}
} It also seems that #216 have suppressed some tests in tokio itself like Line 49 in 68b82f5
|
@Marwes you can detect if a panic happened by adding a The threadpool already internally catches panics, so it should not kill a thread. |
The code is from a test so if it panics for any reason I want to treat that as a test failure. |
I guess panics from futures dispatched onto a separate thread might still be supressed in that case though? 🤔 Is there a reliable way to detect panics even if they are caught on a thread boundary? Or must tests be written in a way to fail despite that? |
What you probably want is to implement a future by hand with a drop impl that checks is the Future was dropped without yielding a value |
This is to work around Tokio's panic recovery feautre. tokio-rs/tokio#495 tokio-rs/tokio#209
This is to work around Tokio's panic recovery feautre. Ref tokio-rs/tokio#495 Ref tokio-rs/tokio#209 Ref denoland#1311 Fixes denoland#2097
This is to work around Tokio's panic recovery feature. Ref tokio-rs/tokio#495 Ref tokio-rs/tokio#209 Ref denoland#1311 Fixes denoland#2097
This is to work around Tokio's panic recovery feature. Ref tokio-rs/tokio#495 Ref tokio-rs/tokio#209 Ref denoland#1311 Fixes denoland#2097
This is to work around Tokio's panic recovery feature. Ref tokio-rs/tokio#495 Ref tokio-rs/tokio#209 Ref #1311 Fixes #2097
This is to work around Tokio's panic recovery feature. Ref tokio-rs/tokio#495 Ref tokio-rs/tokio#209 Ref denoland/deno#1311 Fixes #2097
If this is expected behavior (requiring the user to handle panics), this should definitely documented.
Else and probably better, this should be handled.
The text was updated successfully, but these errors were encountered: