diff --git a/src/admin_rpc.rs b/src/admin_rpc.rs index 0318e799..125f897e 100644 --- a/src/admin_rpc.rs +++ b/src/admin_rpc.rs @@ -182,7 +182,9 @@ impl AdminRpcHandler { self.garage .system .background - .spawn_worker(move |must_exit| async move { self2.repair_worker(must_exit).await }) + .spawn_worker("Repair worker".into(), move |must_exit| async move { + self2.repair_worker(must_exit).await + }) .await; Ok(AdminRPC::Ok(format!( "Repair launched on {:?}", diff --git a/src/background.rs b/src/background.rs index 34e96ff7..b9a4684a 100644 --- a/src/background.rs +++ b/src/background.rs @@ -36,8 +36,8 @@ impl BackgroundRunner { pub async fn run(self: Arc) { let mut workers = self.workers.lock().await; - for _i in 0..self.n_runners { - workers.push(tokio::spawn(self.clone().runner())); + for i in 0..self.n_runners { + workers.push(tokio::spawn(self.clone().runner(i))); } drop(workers); @@ -68,7 +68,7 @@ impl BackgroundRunner { let _: Result<_, _> = self.queue_in.clone().send((boxed, true)); } - pub async fn spawn_worker(&self, worker: F) + pub async fn spawn_worker(&self, name: String, worker: F) where F: FnOnce(watch::Receiver) -> T + Send + 'static, T: Future + Send + 'static, @@ -77,14 +77,14 @@ impl BackgroundRunner { let stop_signal = self.stop_signal.clone(); workers.push(tokio::spawn(async move { if let Err(e) = worker(stop_signal).await { - eprintln!("Worker stopped with error: {}", e); + eprintln!("Worker stopped with error: {}, error: {}", name, e); } else { - println!("A worker exited successfully (which one?)"); + println!("Worker exited successfully: {}", name); } })); } - async fn runner(self: Arc) { + async fn runner(self: Arc, i: usize) { let stop_signal = self.stop_signal.clone(); loop { let must_exit: bool = *stop_signal.borrow(); @@ -94,6 +94,7 @@ impl BackgroundRunner { } } else { if must_exit { + eprintln!("Background runner {} exiting", i); return; } tokio::time::delay_for(Duration::from_secs(1)).await; diff --git a/src/block.rs b/src/block.rs index 11818fd8..81b111ce 100644 --- a/src/block.rs +++ b/src/block.rs @@ -107,11 +107,13 @@ impl BlockManager { pub async fn spawn_background_worker(self: Arc) { // Launch 2 simultaneous workers for background resync loop preprocessing - for _i in 0..2usize { + for i in 0..2usize { let bm2 = self.clone(); self.system .background - .spawn_worker(move |must_exit| bm2.resync_loop(must_exit)) + .spawn_worker(format!("block resync worker {}", i), move |must_exit| { + bm2.resync_loop(must_exit) + }) .await; } } diff --git a/src/membership.rs b/src/membership.rs index fc21d0b5..193b5936 100644 --- a/src/membership.rs +++ b/src/membership.rs @@ -391,7 +391,9 @@ impl System { self.clone() .background - .spawn_worker(|stop_signal| self.ping_loop(stop_signal).map(Ok)) + .spawn_worker(format!("ping loop"), |stop_signal| { + self.ping_loop(stop_signal).map(Ok) + }) .await; } diff --git a/src/table_sync.rs b/src/table_sync.rs index 2fb5de77..a750e04e 100644 --- a/src/table_sync.rs +++ b/src/table_sync.rs @@ -96,18 +96,20 @@ where table .system .background - .spawn_worker(move |must_exit: watch::Receiver| { - s1.watcher_task(must_exit, busy_rx) - }) + .spawn_worker( + format!("table sync watcher for {}", table.name), + move |must_exit: watch::Receiver| s1.watcher_task(must_exit, busy_rx), + ) .await; let s2 = syncer.clone(); table .system .background - .spawn_worker(move |must_exit: watch::Receiver| { - s2.syncer_task(must_exit, busy_tx) - }) + .spawn_worker( + format!("table syncer for {}", table.name), + move |must_exit: watch::Receiver| s2.syncer_task(must_exit, busy_tx), + ) .await; syncer