From bbf1be6eb9466afaa7092d14aa90cf917afcd18c Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Fri, 19 Jan 2024 12:54:37 +0000 Subject: [PATCH] fix: don't start HTTP tracker if it's disabled This fixes this error: ``` Loading default configuration file: `./share/default/config/tracker.development.sqlite3.toml` ... 2024-01-19T12:43:24.605765751+00:00 [torrust_tracker::bootstrap::logging][INFO] logging initialized. 2024-01-19T12:43:24.606305647+00:00 [torrust_tracker::bootstrap::jobs::http_tracker][INFO] Note: Not loading Http Tracker Service, Not Enabled in Configuration. 2024-01-19T12:43:24.606314967+00:00 [torrust_tracker::bootstrap::jobs][INFO] TLS not enabled thread 'tokio-runtime-worker' panicked at src/servers/registar.rs:84:32: it should receive the listing: RecvError(()) ``` --- src/app.rs | 4 ++++ src/servers/apis/server.rs | 12 +++++++++--- src/servers/registar.rs | 10 ++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/app.rs b/src/app.rs index 3ec9806d3..8bdc281a6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -76,6 +76,10 @@ pub async fn start(config: &Configuration, tracker: Arc) -> Vec { let launcher = self.state.launcher; let task = tokio::spawn(async move { - launcher.start(tracker, access_tokens, tx_start, rx_halt).await; + debug!(target: "API", "Starting with launcher in spawned task ..."); + + let _task = launcher.start(tracker, access_tokens, tx_start, rx_halt).await; + + debug!(target: "API", "Started with launcher in spawned task"); + launcher }); @@ -266,9 +271,10 @@ mod tests { #[tokio::test] async fn it_should_be_able_to_start_and_stop() { let cfg = Arc::new(ephemeral_mode_public()); - let tracker = initialize_with_configuration(&cfg); let config = &cfg.http_api; + let tracker = initialize_with_configuration(&cfg); + let bind_to = config .bind_address .parse::() diff --git a/src/servers/registar.rs b/src/servers/registar.rs index 0fb8d6acc..9c23573c4 100644 --- a/src/servers/registar.rs +++ b/src/servers/registar.rs @@ -5,6 +5,7 @@ use std::net::SocketAddr; use std::sync::Arc; use derive_more::Constructor; +use log::debug; use tokio::sync::Mutex; use tokio::task::JoinHandle; @@ -81,10 +82,15 @@ impl Registar { /// Inserts a listing into the registry. async fn insert(&self, rx: tokio::sync::oneshot::Receiver) { - let listing = rx.await.expect("it should receive the listing"); + debug!("Waiting for the started service to send registration data ..."); + + let service_registration = rx + .await + .expect("it should receive the service registration from the started service"); let mut mutex = self.registry.lock().await; - mutex.insert(listing.binding, listing); + + mutex.insert(service_registration.binding, service_registration); } /// Returns the [`ServiceRegistry`] of services