connlib: different backoff strategy for gateway/client (#1910)

With this PR we will keep retrying reconnection forever for the gateway
after it disconnects.
This commit is contained in:
Gabi
2023-08-16 17:05:48 -05:00
committed by GitHub
parent 508b803d98
commit d1537b0839
8 changed files with 26 additions and 3 deletions

5
rust/Cargo.lock generated
View File

@@ -369,9 +369,12 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1"
dependencies = [
"futures-core",
"getrandom",
"instant",
"pin-project-lite",
"rand",
"tokio",
]
[[package]]
@@ -1115,6 +1118,7 @@ name = "firezone-client-connlib"
version = "0.1.0"
dependencies = [
"async-trait",
"backoff",
"boringtun",
"chrono",
"firezone-tunnel",
@@ -1130,6 +1134,7 @@ name = "firezone-gateway-connlib"
version = "0.1.0"
dependencies = [
"async-trait",
"backoff",
"boringtun",
"chrono",
"firezone-tunnel",

View File

@@ -16,6 +16,7 @@ members = [
boringtun = { git = "https://github.com/firezone/boringtun", branch = "master", default-features = false }
chrono = { version = "0.4", default-features = false, features = ["std", "clock", "oldtime", "serde"] }
swift-bridge = "0.1.52"
backoff = { version = "0.4", features = ["tokio"] }
# Patched to use https://github.com/rust-lang/cc-rs/pull/708
# (the `patch` section can't be used for build deps...)

View File

@@ -14,6 +14,7 @@ libs-common = { path = "../common" }
firezone-tunnel = { path = "../tunnel" }
serde = { version = "1.0", default-features = false, features = ["std", "derive"] }
boringtun = { workspace = true }
backoff = { workspace = true }
[dev-dependencies]
serde_json = { version = "1.0", default-features = false, features = ["std"] }

View File

@@ -1,6 +1,7 @@
use std::{sync::Arc, time::Duration};
use crate::messages::{Connect, ConnectionDetails, EgressMessages, InitClient, Messages};
use backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
use boringtun::x25519::StaticSecret;
use libs_common::{
control::{ErrorInfo, ErrorReply, MessageResult, PhoenixSenderWithTopic},
@@ -254,4 +255,8 @@ impl<CB: Callbacks + 'static> ControlSession<Messages, CB> for ControlPlane<CB>
fn socket_path() -> &'static str {
"device"
}
fn retry_strategy() -> ExponentialBackoff {
ExponentialBackoffBuilder::default().build()
}
}

View File

@@ -23,7 +23,7 @@ tokio = { version = "1.28", default-features = false, features = ["rt", "rt-mult
url = { version = "2.3.1", default-features = false }
rand_core = { version = "0.6.4", default-features = false, features = ["std"] }
async-trait = { version = "0.1", default-features = false }
backoff = { version = "0.4", default-features = false }
backoff = { workspace = true }
ip_network = { version = "0.4", default-features = false, features = ["serde"] }
boringtun = { workspace = true }
os_info = { version = "3", default-features = false }

View File

@@ -1,5 +1,5 @@
use async_trait::async_trait;
use backoff::{backoff::Backoff, ExponentialBackoffBuilder};
use backoff::{backoff::Backoff, ExponentialBackoff};
use boringtun::x25519::{PublicKey, StaticSecret};
use ip_network::IpNetwork;
use parking_lot::Mutex;
@@ -40,6 +40,9 @@ pub trait ControlSession<T, CB: Callbacks> {
/// Either "gateway" or "client" used to get the control-plane URL.
fn socket_path() -> &'static str;
/// Retry strategy in case of disconnection for the session.
fn retry_strategy() -> ExponentialBackoff;
}
// TODO: Currently I'm using Session for both gateway and clients
@@ -306,7 +309,7 @@ where
);
tokio::spawn(async move {
let mut exponential_backoff = ExponentialBackoffBuilder::default().build();
let mut exponential_backoff = T::retry_strategy();
loop {
// `connection.start` calls the callback only after connecting
let result = connection.start(vec![topic.clone()], || exponential_backoff.reset()).await;

View File

@@ -12,6 +12,7 @@ tracing = { version = "0.1", default-features = false, features = ["std", "attri
serde = { version = "1.0", default-features = false, features = ["std", "derive"] }
boringtun = { workspace = true }
chrono = { workspace = true }
backoff = { workspace = true }
[dev-dependencies]
serde_json = { version = "1.0", default-features = false, features = ["std"] }

View File

@@ -1,5 +1,6 @@
use std::{sync::Arc, time::Duration};
use backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
use boringtun::x25519::StaticSecret;
use firezone_tunnel::{ControlSignal, Tunnel};
use libs_common::{
@@ -164,4 +165,10 @@ impl<CB: Callbacks + 'static> ControlSession<IngressMessages, CB> for ControlPla
fn socket_path() -> &'static str {
"gateway"
}
fn retry_strategy() -> ExponentialBackoff {
ExponentialBackoffBuilder::default()
.with_max_elapsed_time(None)
.build()
}
}