From c057605eb727bcafcb96c87833dd392575683edc Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 10 Aug 2024 05:25:21 +0100 Subject: [PATCH] fix(awc): prevent panics in pool drop for h1 connections --- awc/CHANGES.md | 2 ++ awc/src/client/pool.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 9c0f3b607..037d38739 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 1736f2b02..5d764f729 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)); + } } } }