From 8a0f1ab2306a1c19fd88d09d58a7354804084001 Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Fri, 8 Nov 2024 15:51:04 -0800 Subject: [PATCH] fix(pool): add timeout to `return_to_pool()` --- sqlx-core/src/pool/connection.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sqlx-core/src/pool/connection.rs b/sqlx-core/src/pool/connection.rs index 55133bf8..00ffd792 100644 --- a/sqlx-core/src/pool/connection.rs +++ b/sqlx-core/src/pool/connection.rs @@ -13,7 +13,10 @@ use crate::error::Error; use super::inner::{is_beyond_max_lifetime, PoolInner}; use crate::pool::connect::{ConnectPermit, ConnectionId}; use crate::pool::options::PoolConnectionMetadata; +use crate::rt; +use std::future::Future; +const RETURN_TO_POOL_TIMEOUT: Duration = Duration::from_secs(5); const CLOSE_ON_DROP_TIMEOUT: Duration = Duration::from_secs(5); /// A connection managed by a [`Pool`][crate::pool::Pool]. @@ -149,7 +152,9 @@ impl PoolConnection { async move { let returned_to_pool = if let Some(floating) = floating { - floating.return_to_pool().await + rt::timeout(RETURN_TO_POOL_TIMEOUT, floating.return_to_pool()) + .await + .unwrap_or(false) } else { false };