diff --git a/rust/connlib/clients/android/src/lib.rs b/rust/connlib/clients/android/src/lib.rs index e755d3909..3bd3bf680 100644 --- a/rust/connlib/clients/android/src/lib.rs +++ b/rust/connlib/clients/android/src/lib.rs @@ -351,7 +351,6 @@ fn connect( portal_url.as_str(), portal_token, device_id, - None, callback_handler, ) .map_err(Into::into) diff --git a/rust/connlib/clients/apple/src/lib.rs b/rust/connlib/clients/apple/src/lib.rs index bf5424eeb..70cec2d15 100644 --- a/rust/connlib/clients/apple/src/lib.rs +++ b/rust/connlib/clients/apple/src/lib.rs @@ -64,6 +64,7 @@ mod ffi { /// This is used by the apple client to interact with our code. pub struct WrappedSession { session: Session, + _guard: WorkerGuard, } // SAFETY: `CallbackHandler.swift` promises to be thread-safe. @@ -157,15 +158,17 @@ impl WrappedSession { log_dir: String, callback_handler: ffi::CallbackHandler, ) -> Result { - Session::connect( + let _guard = init_logging(log_dir.into()); + + let session = Session::connect( portal_url.as_str(), token, device_id, - Some(init_logging(log_dir.into())), CallbackHandler(callback_handler.into()), ) - .map(|session| Self { session }) - .map_err(|err| err.to_string()) + .map_err(|err| err.to_string())?; + + Ok(Self { session, _guard }) } fn disconnect(&mut self) { diff --git a/rust/connlib/clients/headless/src/main.rs b/rust/connlib/clients/headless/src/main.rs index 48c74b141..0ca9d0b24 100644 --- a/rust/connlib/clients/headless/src/main.rs +++ b/rust/connlib/clients/headless/src/main.rs @@ -101,15 +101,9 @@ fn main() -> Result<()> { let secret = parse_env_var::(SECRET_ENV_VAR)?; let device_id = get_device_id(); let log_dir = parse_env_var::(LOG_DIR_ENV_VAR).unwrap_or(DEFAULT_LOG_DIR.into()); + let _guard = init_logging(log_dir); - let mut session = Session::connect( - url, - secret, - device_id, - Some(init_logging(log_dir)), - CallbackHandler, - ) - .unwrap(); + let mut session = Session::connect(url, secret, device_id, CallbackHandler).unwrap(); tracing::info!("Started new session"); block_on_ctrl_c(); diff --git a/rust/connlib/gateway/src/main.rs b/rust/connlib/gateway/src/main.rs index 4e3700157..95df94156 100644 --- a/rust/connlib/gateway/src/main.rs +++ b/rust/connlib/gateway/src/main.rs @@ -67,7 +67,7 @@ fn main() -> Result<()> { let url = parse_env_var::(URL_ENV_VAR)?; let secret = parse_env_var::(SECRET_ENV_VAR)?; let device_id = get_device_id(); - let mut session = Session::connect(url, secret, device_id, None, CallbackHandler).unwrap(); + let mut session = Session::connect(url, secret, device_id, CallbackHandler).unwrap(); let (tx, rx) = std::sync::mpsc::channel(); ctrlc::set_handler(move || tx.send(()).expect("Could not send stop signal on channel.")) diff --git a/rust/connlib/libs/common/src/session.rs b/rust/connlib/libs/common/src/session.rs index 1ab4fcb07..39a32eaaf 100644 --- a/rust/connlib/libs/common/src/session.rs +++ b/rust/connlib/libs/common/src/session.rs @@ -20,7 +20,6 @@ use crate::{ messages::{Key, ResourceDescription}, Error, Result, }; -use tracing_appender::non_blocking::WorkerGuard; pub const DNS_SENTINEL: Ipv4Addr = Ipv4Addr::new(100, 100, 111, 1); @@ -56,9 +55,6 @@ pub trait ControlSession { /// A session is created using [Session::connect], then to stop a session we use [Session::disconnect]. pub struct Session { runtime_stopper: tokio::sync::mpsc::Sender, - // The guard must not be dropped before the runtime is dropped, otherwise logs won't get - // flushed to the logfile. - _logging_guard: Option, pub callbacks: CallbackErrorFacade, _phantom: PhantomData<(T, U, V, R, M)>, } @@ -221,7 +217,6 @@ where portal_url: impl TryInto, token: String, device_id: String, - _logging_guard: Option, callbacks: CB, ) -> Result { // TODO: We could use tokio::runtime::current() to get the current runtime @@ -234,7 +229,6 @@ where let (tx, mut rx) = tokio::sync::mpsc::channel(1); let this = Self { runtime_stopper: tx.clone(), - _logging_guard, callbacks, _phantom: PhantomData, };