Skip to content

Commit

Permalink
Expose connection pool's get timeout via ConnectionOptionsBuilder (wo…
Browse files Browse the repository at this point in the history
  • Loading branch information
criminosis authored May 13, 2024
1 parent 8c439a1 commit e729960
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 4 additions & 1 deletion gremlin-client/src/aio/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ impl GremlinClient {
let pool_size = opts.pool_size;
let manager = GremlinConnectionManager::new(opts.clone());

let pool = Pool::builder().max_open(pool_size as u64).build(manager);
let pool = Pool::builder()
.get_timeout(opts.pool_get_connection_timeout)
.max_open(pool_size as u64)
.build(manager);

Ok(GremlinClient {
pool,
Expand Down
8 changes: 6 additions & 2 deletions gremlin-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ impl GremlinClient {
let pool_size = opts.pool_size;
let manager = GremlinConnectionManager::new(opts.clone());

let pool = Pool::builder().max_size(pool_size).build(manager)?;
let mut pool_builder = Pool::builder().max_size(pool_size);

if let Some(get_connection_timeout) = opts.pool_get_connection_timeout {
pool_builder = pool_builder.connection_timeout(get_connection_timeout);
}

Ok(GremlinClient {
pool,
pool: pool_builder.build(manager)?,
session: None,
alias: None,
options: opts,
Expand Down
11 changes: 10 additions & 1 deletion gremlin-client/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::net::TcpStream;
use std::{net::TcpStream, time::Duration};

use crate::{GraphSON, GremlinError, GremlinResult};
use native_tls::TlsConnector;
Expand Down Expand Up @@ -120,6 +120,13 @@ impl ConnectionOptionsBuilder {
self
}

/// Both the sync and async pool providers use a default of 30 seconds,
/// Async pool interprets `None` as no timeout. Sync pool maps `None` to the default value
pub fn pool_connection_timeout(mut self, pool_connection_timeout: Option<Duration>) -> Self {
self.0.pool_get_connection_timeout = pool_connection_timeout;
self
}

pub fn build(self) -> ConnectionOptions {
self.0
}
Expand Down Expand Up @@ -163,6 +170,7 @@ pub struct ConnectionOptions {
pub(crate) host: String,
pub(crate) port: u16,
pub(crate) pool_size: u32,
pub(crate) pool_get_connection_timeout: Option<Duration>,
pub(crate) credentials: Option<Credentials>,
pub(crate) ssl: bool,
pub(crate) tls_options: Option<TlsOptions>,
Expand Down Expand Up @@ -245,6 +253,7 @@ impl Default for ConnectionOptions {
host: String::from("localhost"),
port: 8182,
pool_size: 10,
pool_get_connection_timeout: Some(Duration::from_secs(30)),
credentials: None,
ssl: false,
tls_options: None,
Expand Down

0 comments on commit e729960

Please sign in to comment.