diff --git a/CHANGELOG.md b/CHANGELOG.md index ecd5690..777cb9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,12 @@ All notable changes to this project will be documented in this file. ago before marking it as `ready` ([#68]). - Emit less attributes in tracing to make logs easier readable ([#86]). +### 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 [#86]: https://github.com/stackabletech/trino-lb/pull/86 ## [0.5.0] - 2025-03-14 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)?;