From 1108235c632476a746a19ef39822e926f7d4b94f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 25 May 2024 20:16:28 +0000 Subject: [PATCH] misc simplifications and cleanup Signed-off-by: Jason Volk --- src/main/main.rs | 17 ++++++++--------- src/main/server.rs | 6 ++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/main.rs b/src/main/main.rs index a96945a7..ba1cb2d3 100644 --- a/src/main/main.rs +++ b/src/main/main.rs @@ -25,21 +25,20 @@ fn main() -> Result<(), Error> { .build() .expect("built runtime"); - let handle = runtime.handle(); - let server: Arc = Server::build(args, Some(handle))?; - runtime.block_on(async { async_main(server.clone()).await })?; + let server: Arc = Server::build(args, Some(runtime.handle()))?; + runtime.block_on(async_main(&server))?; // explicit drop here to trace thread and tls dtors drop(runtime); - debug_info!("Exit"); + Ok(()) } /// Operate the server normally in release-mode static builds. This will start, /// run and stop the server within the asynchronous runtime. #[cfg(not(conduit_mods))] -async fn async_main(server: Arc) -> Result<(), Error> { +async fn async_main(server: &Arc) -> Result<(), Error> { extern crate conduit_router as router; use tracing::error; @@ -66,22 +65,22 @@ async fn async_main(server: Arc) -> Result<(), Error> { /// and hot-reload portions of the server as-needed before returning for an /// actual shutdown. This is not available in release-mode or static builds. #[cfg(conduit_mods)] -async fn async_main(server: Arc) -> Result<(), Error> { +async fn async_main(server: &Arc) -> Result<(), Error> { let mut starts = true; let mut reloads = true; while reloads { - if let Err(error) = mods::open(&server).await { + if let Err(error) = mods::open(server).await { error!("Loading router: {error}"); return Err(error); } - let result = mods::run(&server, starts).await; + let result = mods::run(server, starts).await; if let Ok(result) = result { (starts, reloads) = result; } let force = !reloads || result.is_err(); - if let Err(error) = mods::close(&server, force).await { + if let Err(error) = mods::close(server, force).await { error!("Unloading router: {error}"); return Err(error); } diff --git a/src/main/server.rs b/src/main/server.rs index 2395469b..d960bfac 100644 --- a/src/main/server.rs +++ b/src/main/server.rs @@ -139,9 +139,7 @@ fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) { let (flame_layer, flame_guard) = match tracing_flame::FlameLayer::with_file(&config.tracing_flame_output_path) { Ok(ok) => ok, - Err(e) => { - panic!("failed to initialize tracing-flame: {e}"); - }, + Err(e) => panic!("failed to initialize tracing-flame: {e}"), }; let flame_layer = flame_layer .with_empty_samples(false) @@ -175,7 +173,7 @@ fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) { #[cfg_attr(not(feature = "perf_measurements"), allow(clippy::let_unit_value))] let flame_guard = (); - tracing::subscriber::set_global_default(subscriber).unwrap(); + tracing::subscriber::set_global_default(subscriber).expect("failed to set global tracing subscriber"); #[cfg(all(feature = "tokio_console", feature = "release_max_log_level", tokio_unstable))] tracing::error!(