-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[awc 3.0.0-beta.5] panic on exit if awc::Client
is kept in a thread_local!{}
#2207
Comments
You didn't get panic in awc v2 because it was silently leaking tcp connections on drop. I don't think your suggested solution is a good one. If you are holding a awc client object longer than it's runtime I believe a panic is a good way to tell you are doing it wrong. |
If it's properly closing the file descriptors on-drop (which it should be doing anyway) then nothing is being "leaked" here, you're just losing the graceful shutdown message sent by For example, Tokio does not care one single bit if you drop a //# anyhow = "1.0"
//# tokio = { version = "1.0", features = ["net", "rt-multi-thread"] }
use tokio::net::TcpStream;
use tokio::runtime::Runtime;
fn main() -> anyhow::Result<()> {
// nslookup google.com
let stream =
Runtime::new()?.block_on(async { TcpStream::connect("172.217.164.110:443").await })?;
drop(stream);
Ok(())
} Panics should be reserved for signaling actual bugs. |
awc does not only hold Holding an awc object that can go outside the context of it's runtime is a bug. |
Attempting to use it outside the runtime is a bug, certainly, which is why I'm not complaining about panics in general. However, we're talking about a Here's the actual culprit after looking at the stack trace again (which I admittedly trimmed down too much; it's not even in Also, it looks like if |
That's an orthogonal issue? If the HTTP/2 connection isn't cleaned up when the runtime is dropped that's a bug in how HTTP/2 connections are handled. |
I'm not saying to never run the |
This is my point. This kind of issue always come down to the lack of async drop in Rust. There are people prefer to hack a way by skipping, there are people prefer to block the thread and do drop. I'm not saying they are wrong it's just not my preference. Doing spawn task in Drop is not right either but I find it's one of the few ways work in situation like this. |
Given that it needs We already migrated our remaining uses of |
For convenience, we have a function at the root of our crate that returns an
awc::Client
which caches it in a thread-local and returns it:This worked fine with
actix-web 3.*
usingawc 2.*
but upon upgrading toawc 3.0.0-beta.5
we noticed panics on exit:What appears to be happening is that the
thread_local!
is trying to run the destructor onawc::Client
on exit of the thread, which is trying to gracefully close its internally held TCP connections, but the Tokio runtime has already gone away because the thread is exiting and sotokio::runtime::Handle::current()
is panicking.Suggested Solution
The destructor of
awc::Client
or whatever internal structure that is trying to close TCP connections on-drop needs to useHandle::try_current()
so as to not panic if the Tokio runtime is exiting, and if it can't get a handle to the runtime it should just exit without trying to gracefully close any connections.Your Environment
rustc -V
): 1.52.1awc 3.0.0-beta.5
The text was updated successfully, but these errors were encountered: