Skip to content

Commit 5b8074d

Browse files
committed
sbuilder: add hostname_resolution_timeout option
This option is responsible for setting the DNS hostname resolution timeout. The default timeout is set to 5 seconds.
1 parent 64b4afc commit 5b8074d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

scylla/src/transport/session.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ pub struct SessionConfig {
252252
/// It is true by default but can be disabled if successive schema-altering statements should be performed.
253253
pub refresh_metadata_on_auto_schema_agreement: bool,
254254

255+
/// DNS hostname resolution timeout.
256+
/// If `None`, the driver will wait for hostname resolution indefinitely.
257+
pub hostname_resolution_timeout: Option<Duration>,
258+
255259
/// The address translator is used to translate addresses received from ScyllaDB nodes
256260
/// (either with cluster metadata or with an event) to addresses that can be used to
257261
/// actually connect to those nodes. This may be needed e.g. when there is NAT
@@ -332,6 +336,7 @@ impl SessionConfig {
332336
ssl_context: None,
333337
authenticator: None,
334338
connect_timeout: Duration::from_secs(5),
339+
hostname_resolution_timeout: Some(Duration::from_secs(5)),
335340
connection_pool_size: Default::default(),
336341
disallow_shard_aware_port: false,
337342
keyspaces_to_fetch: Vec::new(),

scylla/src/transport/session_builder.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,27 @@ impl<K: SessionBuilderKind> GenericSessionBuilder<K> {
762762
self
763763
}
764764

765+
/// Changes DNS hostname resolution timeout.
766+
/// The default is 5 seconds.
767+
///
768+
/// # Example
769+
/// ```
770+
/// # use scylla::{Session, SessionBuilder};
771+
/// # use std::time::Duration;
772+
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
773+
/// let session: Session = SessionBuilder::new()
774+
/// .known_node("127.0.0.1:9042")
775+
/// .hostname_resolution_timeout(Duration::from_secs(10))
776+
/// .build() // Turns SessionBuilder into Session
777+
/// .await?;
778+
/// # Ok(())
779+
/// # }
780+
/// ```
781+
pub fn hostname_resolution_timeout(mut self, duration: Duration) -> Self {
782+
self.config.hostname_resolution_timeout = Some(duration);
783+
self
784+
}
785+
765786
/// Sets the host filter. The host filter decides whether any connections
766787
/// should be opened to the node or not. The driver will also avoid
767788
/// those nodes when re-establishing the control connection.

0 commit comments

Comments
 (0)