Skip to content

Commit bbf1be6

Browse files
committed
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(()) ```
1 parent 203ce96 commit bbf1be6

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/app.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ pub async fn start(config: &Configuration, tracker: Arc<core::Tracker>) -> Vec<J
7676

7777
// Start the HTTP blocks
7878
for http_tracker_config in &config.http_trackers {
79+
if !http_tracker_config.enabled {
80+
continue;
81+
}
82+
7983
if let Some(job) = http_tracker::start_job(
8084
http_tracker_config,
8185
tracker.clone(),

src/servers/apis/server.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use axum_server::tls_rustls::RustlsConfig;
3030
use axum_server::Handle;
3131
use derive_more::Constructor;
3232
use futures::future::BoxFuture;
33-
use log::{error, info};
33+
use log::{debug, error, info};
3434
use tokio::sync::oneshot::{Receiver, Sender};
3535
use torrust_tracker_configuration::AccessTokens;
3636

@@ -120,7 +120,12 @@ impl ApiServer<Stopped> {
120120
let launcher = self.state.launcher;
121121

122122
let task = tokio::spawn(async move {
123-
launcher.start(tracker, access_tokens, tx_start, rx_halt).await;
123+
debug!(target: "API", "Starting with launcher in spawned task ...");
124+
125+
let _task = launcher.start(tracker, access_tokens, tx_start, rx_halt).await;
126+
127+
debug!(target: "API", "Started with launcher in spawned task");
128+
124129
launcher
125130
});
126131

@@ -266,9 +271,10 @@ mod tests {
266271
#[tokio::test]
267272
async fn it_should_be_able_to_start_and_stop() {
268273
let cfg = Arc::new(ephemeral_mode_public());
269-
let tracker = initialize_with_configuration(&cfg);
270274
let config = &cfg.http_api;
271275

276+
let tracker = initialize_with_configuration(&cfg);
277+
272278
let bind_to = config
273279
.bind_address
274280
.parse::<std::net::SocketAddr>()

src/servers/registar.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::net::SocketAddr;
55
use std::sync::Arc;
66

77
use derive_more::Constructor;
8+
use log::debug;
89
use tokio::sync::Mutex;
910
use tokio::task::JoinHandle;
1011

@@ -81,10 +82,15 @@ impl Registar {
8182

8283
/// Inserts a listing into the registry.
8384
async fn insert(&self, rx: tokio::sync::oneshot::Receiver<ServiceRegistration>) {
84-
let listing = rx.await.expect("it should receive the listing");
85+
debug!("Waiting for the started service to send registration data ...");
86+
87+
let service_registration = rx
88+
.await
89+
.expect("it should receive the service registration from the started service");
8590

8691
let mut mutex = self.registry.lock().await;
87-
mutex.insert(listing.binding, listing);
92+
93+
mutex.insert(service_registration.binding, service_registration);
8894
}
8995

9096
/// Returns the [`ServiceRegistry`] of services

0 commit comments

Comments
 (0)