Skip to content

Commit

Permalink
Move default private connect timeout to Config (#42)
Browse files Browse the repository at this point in the history
Previously the default value of this setting was in lib.rs instead of
being automatically set in `Config` like all the other defaults, which
was inconsistent and confusing.

Fix this by moving the defaulting logic to `Config`.

Validated by running the test suite.
  • Loading branch information
briansmith committed Dec 14, 2017
1 parent 0c2aa0e commit 81fb0fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 5 additions & 2 deletions proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Config {
pub public_connect_timeout: Option<Duration>,

/// The maximum amount of time to wait for a connection to the private peer.
pub private_connect_timeout: Option<Duration>,
pub private_connect_timeout: Duration,

/// The path to "/etc/resolv.conf"
pub resolv_conf_path: PathBuf,
Expand Down Expand Up @@ -143,6 +143,7 @@ const DEFAULT_REPORT_TIMEOUT_SECS: u64 = 10; // TODO: is this a reasonable defau
const DEFAULT_PRIVATE_LISTENER: &str = "tcp://127.0.0.1:4140";
const DEFAULT_PUBLIC_LISTENER: &str = "tcp://0.0.0.0:4143";
const DEFAULT_CONTROL_LISTENER: &str = "tcp://0.0.0.0:4190";
const DEFAULT_PRIVATE_CONNECT_TIMEOUT_MS: u64 = 20;
const DEFAULT_CONTROL_URL: &str = "tcp://proxy-api.conduit.svc.cluster.local:8086";
const DEFAULT_RESOLV_CONF: &str = "/etc/resolv.conf";

Expand Down Expand Up @@ -186,7 +187,9 @@ impl<'a> TryFrom<&'a Strings> for Config {
},
private_forward: private_forward?,
public_connect_timeout: public_connect_timeout?.map(Duration::from_millis),
private_connect_timeout: private_connect_timeout?.map(Duration::from_millis),
private_connect_timeout:
Duration::from_millis(private_connect_timeout?
.unwrap_or(DEFAULT_PRIVATE_CONNECT_TIMEOUT_MS)),
resolv_conf_path: resolv_conf_path?
.unwrap_or(DEFAULT_RESOLV_CONF.into())
.into(),
Expand Down
11 changes: 4 additions & 7 deletions proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use std::io;
use std::net::SocketAddr;
use std::sync::Arc;
use std::thread;
use std::time::{Duration, Instant};
use std::time::Instant;

use tokio_core::reactor::{Core, Handle};
use tower::NewService;
Expand Down Expand Up @@ -176,11 +176,8 @@ impl Main {
let inbound = {
let ctx = ctx::Proxy::inbound(&process_ctx);

let timeout = config
.private_connect_timeout
.unwrap_or_else(|| Duration::from_millis(20));
let bind = bind.clone()
.with_connect_timeout(timeout)
.with_connect_timeout(config.private_connect_timeout)
.with_ctx(ctx.clone());

let default_addr = config.private_forward.map(|a| a.into());
Expand Down Expand Up @@ -244,8 +241,8 @@ impl Main {
.expect("bad news in telemetry town");

let client = control_bg.bind(
telemetry,
control_host_and_port,
telemetry,
control_host_and_port,
dns_config,
config.report_timeout,
&executor
Expand Down

0 comments on commit 81fb0fe

Please sign in to comment.