From 7feb0d1a80227c6992e488fdbda9b78769741f25 Mon Sep 17 00:00:00 2001 From: Alek Westover Date: Fri, 21 Jul 2023 15:17:16 -0400 Subject: [PATCH] `unwrap` instead of passing `anyhow::Error` on failure to spawn a thread (#4779) --- compute_tools/src/bin/compute_ctl.rs | 5 ++--- compute_tools/src/configurator.rs | 8 ++++---- compute_tools/src/monitor.rs | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/compute_tools/src/bin/compute_ctl.rs b/compute_tools/src/bin/compute_ctl.rs index 68f6bf3844..4953e5f331 100644 --- a/compute_tools/src/bin/compute_ctl.rs +++ b/compute_tools/src/bin/compute_ctl.rs @@ -223,9 +223,8 @@ fn main() -> Result<()> { drop(state); // Launch remaining service threads - let _monitor_handle = launch_monitor(&compute).expect("cannot launch compute monitor thread"); - let _configurator_handle = - launch_configurator(&compute).expect("cannot launch configurator thread"); + let _monitor_handle = launch_monitor(&compute); + let _configurator_handle = launch_configurator(&compute); // Start Postgres let mut delay_exit = false; diff --git a/compute_tools/src/configurator.rs b/compute_tools/src/configurator.rs index 13550e0176..274a221ac7 100644 --- a/compute_tools/src/configurator.rs +++ b/compute_tools/src/configurator.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use std::thread; -use anyhow::Result; use tracing::{error, info, instrument}; use compute_api::responses::ComputeStatus; @@ -42,13 +41,14 @@ fn configurator_main_loop(compute: &Arc) { } } -pub fn launch_configurator(compute: &Arc) -> Result> { +pub fn launch_configurator(compute: &Arc) -> thread::JoinHandle<()> { let compute = Arc::clone(compute); - Ok(thread::Builder::new() + thread::Builder::new() .name("compute-configurator".into()) .spawn(move || { configurator_main_loop(&compute); info!("configurator thread is exited"); - })?) + }) + .expect("cannot launch configurator thread") } diff --git a/compute_tools/src/monitor.rs b/compute_tools/src/monitor.rs index d2e7b698dd..1085a27902 100644 --- a/compute_tools/src/monitor.rs +++ b/compute_tools/src/monitor.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use std::{thread, time}; -use anyhow::Result; use chrono::{DateTime, Utc}; use postgres::{Client, NoTls}; use tracing::{debug, info}; @@ -105,10 +104,11 @@ fn watch_compute_activity(compute: &ComputeNode) { } /// Launch a separate compute monitor thread and return its `JoinHandle`. -pub fn launch_monitor(state: &Arc) -> Result> { +pub fn launch_monitor(state: &Arc) -> thread::JoinHandle<()> { let state = Arc::clone(state); - Ok(thread::Builder::new() + thread::Builder::new() .name("compute-monitor".into()) - .spawn(move || watch_compute_activity(&state))?) + .spawn(move || watch_compute_activity(&state)) + .expect("cannot launch compute monitor thread") }