From c05572399799e8c2d961209a03026eb291166c42 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 18 Aug 2024 15:54:36 +0100 Subject: [PATCH] fix(awc): prevent panics in pool drop for h1 connections (#3448) --- awc/CHANGES.md | 1 + awc/src/client/pool.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/awc/CHANGES.md b/awc/CHANGES.md index a2e51c8d2..11cb150ab 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -2,6 +2,7 @@ ## Unreleased +- Prevent panics on connection pool drop when Tokio runtime is shutdown early. - Minimum supported Rust version (MSRV) is now 1.75. ## 3.5.1 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)); + } } } }