Skip to content

Commit

Permalink
fix: don't start HTTP tracker if it's disabled
Browse files Browse the repository at this point in the history
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(())
```
  • Loading branch information
josecelano committed Jan 19, 2024
1 parent 203ce96 commit bbf1be6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ pub async fn start(config: &Configuration, tracker: Arc<core::Tracker>) -> Vec<J

// Start the HTTP blocks
for http_tracker_config in &config.http_trackers {
if !http_tracker_config.enabled {

Check warning on line 79 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L79

Added line #L79 was not covered by tests
continue;
}

if let Some(job) = http_tracker::start_job(
http_tracker_config,
tracker.clone(),
Expand Down
12 changes: 9 additions & 3 deletions src/servers/apis/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use axum_server::tls_rustls::RustlsConfig;
use axum_server::Handle;
use derive_more::Constructor;
use futures::future::BoxFuture;
use log::{error, info};
use log::{debug, error, info};
use tokio::sync::oneshot::{Receiver, Sender};
use torrust_tracker_configuration::AccessTokens;

Expand Down Expand Up @@ -120,7 +120,12 @@ impl ApiServer<Stopped> {
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
});

Expand Down Expand Up @@ -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::<std::net::SocketAddr>()
Expand Down
10 changes: 8 additions & 2 deletions src/servers/registar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -81,10 +82,15 @@ impl Registar {

/// Inserts a listing into the registry.
async fn insert(&self, rx: tokio::sync::oneshot::Receiver<ServiceRegistration>) {
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
Expand Down

0 comments on commit bbf1be6

Please sign in to comment.