Skip to content

fix: Set connection and response timeout for Redis connections #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions trino-lb-persistence/src/redis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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();
Expand Down Expand Up @@ -139,9 +142,13 @@ impl RedisPersistence<ConnectionManager> {
})?;
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)?;

Expand All @@ -160,11 +167,15 @@ impl RedisPersistence<ClusterConnection<MultiplexedConnection>> {
})?;
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)?;

Expand Down
Loading