From dfc8ca0c365ad756eac4cdb894d9aed2dcad9da8 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Mon, 12 May 2025 10:53:01 +0200 Subject: [PATCH 1/2] fix: Set connection and response timeout for Redis connections --- trino-lb-persistence/src/redis/mod.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/trino-lb-persistence/src/redis/mod.rs b/trino-lb-persistence/src/redis/mod.rs index d0c6de1..7d5f980 100644 --- a/trino-lb-persistence/src/redis/mod.rs +++ b/trino-lb-persistence/src/redis/mod.rs @@ -7,8 +7,8 @@ use std::{ use futures::{TryFutureExt, future::try_join_all}; use redis::{ AsyncCommands, Client, RedisError, Script, - aio::{ConnectionManager, MultiplexedConnection}, - cluster::ClusterClientBuilder, + aio::{ConnectionManager, ConnectionManagerConfig, MultiplexedConnection}, + cluster::{ClusterClientBuilder, ClusterConfig}, cluster_async::ClusterConnection, }; use snafu::{OptionExt, ResultExt, Snafu}; @@ -23,6 +23,9 @@ use url::Url; use crate::Persistence; +const REDIS_CONNECTION_TIMEOUT: Duration = Duration::from_secs(10); +const REDIS_RESPONSE_TIMEOUT: Duration = Duration::from_secs(10); + const LAST_QUERY_COUNT_FETCHER_UPDATE_KEY: &str = "lastQueryCountFetcherUpdate"; const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard(); @@ -139,9 +142,13 @@ impl RedisPersistence { })?; info!(redis_host, "Using redis persistence"); + let redis_config = ConnectionManagerConfig::new() + .set_connection_timeout(REDIS_CONNECTION_TIMEOUT) + .set_response_timeout(REDIS_RESPONSE_TIMEOUT); + let client = Client::open(config.endpoint.as_str()).context(CreateClientSnafu)?; let connection = client - .get_connection_manager() + .get_connection_manager_with_config(redis_config) .await .context(CreateClientSnafu)?; @@ -160,11 +167,15 @@ impl RedisPersistence> { })?; info!(redis_host, "Using redis cluster persistence"); + let redis_config = ClusterConfig::new() + .set_connection_timeout(REDIS_CONNECTION_TIMEOUT) + .set_response_timeout(REDIS_RESPONSE_TIMEOUT); + let client = ClusterClientBuilder::new([config.endpoint.as_str()]) .build() .context(CreateClientSnafu)?; let connection = client - .get_async_connection() + .get_async_connection_with_config(redis_config) .await .context(CreateClientSnafu)?; From 1771e3d5b4c133414d39f1d1c3bfffd4f16d1688 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Mon, 12 May 2025 11:17:22 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e81ef40..e5a13ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,12 @@ All notable changes to this project will be documented in this file. - The Stackable scaler now ensures that a `TrinoCluster` has changed to `ready` more than 5 seconds ago before marking it as `ready` ([#68]). +### Fixed + +- Set connection and response timeout for Redis connections ([#85]). + [#68]: https://github.com/stackabletech/trino-lb/pull/68 +[#85]: https://github.com/stackabletech/trino-lb/pull/85 ## [0.5.0] - 2025-03-14