diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 9c0f3b6078c..037d387393a 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Prevent panics on connection pool drop when Tokio runtime is shutdown early. + ## 3.5.1 - Fix WebSocket `Host` request header value when using a non-default port. diff --git a/awc/src/client/pool.rs b/awc/src/client/pool.rs index 1736f2b020a..5d764f72936 100644 --- a/awc/src/client/pool.rs +++ b/awc/src/client/pool.rs @@ -76,7 +76,9 @@ where fn close(&self, conn: ConnectionInnerType) { if let Some(timeout) = self.config.disconnect_timeout { if let ConnectionInnerType::H1(io) = conn { - actix_rt::spawn(CloseConnection::new(io, timeout)); + if tokio::runtime::Handle::try_current().is_ok() { + actix_rt::spawn(CloseConnection::new(io, timeout)); + } } } }