Skip to content

Commit

Permalink
sbuilder: add hostname_resolution_timeout option
Browse files Browse the repository at this point in the history
This option is responsible for setting the DNS hostname
resolution timeout.

The default timeout is set to 5 seconds.
  • Loading branch information
muzarski committed Oct 30, 2024
1 parent 64b4afc commit 5b8074d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scylla/src/transport/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ pub struct SessionConfig {
/// It is true by default but can be disabled if successive schema-altering statements should be performed.
pub refresh_metadata_on_auto_schema_agreement: bool,

/// DNS hostname resolution timeout.
/// If `None`, the driver will wait for hostname resolution indefinitely.
pub hostname_resolution_timeout: Option<Duration>,

/// The address translator is used to translate addresses received from ScyllaDB nodes
/// (either with cluster metadata or with an event) to addresses that can be used to
/// actually connect to those nodes. This may be needed e.g. when there is NAT
Expand Down Expand Up @@ -332,6 +336,7 @@ impl SessionConfig {
ssl_context: None,
authenticator: None,
connect_timeout: Duration::from_secs(5),
hostname_resolution_timeout: Some(Duration::from_secs(5)),
connection_pool_size: Default::default(),
disallow_shard_aware_port: false,
keyspaces_to_fetch: Vec::new(),
Expand Down
21 changes: 21 additions & 0 deletions scylla/src/transport/session_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,27 @@ impl<K: SessionBuilderKind> GenericSessionBuilder<K> {
self
}

/// Changes DNS hostname resolution timeout.
/// The default is 5 seconds.
///
/// # Example
/// ```
/// # use scylla::{Session, SessionBuilder};
/// # use std::time::Duration;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let session: Session = SessionBuilder::new()
/// .known_node("127.0.0.1:9042")
/// .hostname_resolution_timeout(Duration::from_secs(10))
/// .build() // Turns SessionBuilder into Session
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn hostname_resolution_timeout(mut self, duration: Duration) -> Self {
self.config.hostname_resolution_timeout = Some(duration);
self
}

/// Sets the host filter. The host filter decides whether any connections
/// should be opened to the node or not. The driver will also avoid
/// those nodes when re-establishing the control connection.
Expand Down

0 comments on commit 5b8074d

Please sign in to comment.