From d1c5d5203bad5d76862ca303a563748e514859b4 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 15:41:45 -0300 Subject: [PATCH 1/2] Don't run server in tokio::spawn --- magic-nix-cache/src/main.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index fb97e3c..1a0d370 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -371,21 +371,6 @@ async fn main_cli() -> Result<()> { tracing::info!("Listening on {}", args.listen); - let server = axum::Server::bind(&args.listen) - .serve(app.into_make_service()) - .with_graceful_shutdown(async move { - shutdown_receiver.await.ok(); - tracing::info!("Shutting down"); - }); - - // Spawn here so that post-startup tasks can proceed - tokio::spawn(async move { - if let Err(e) = server.await { - tracing::error!("failed to start up daemon: {e}"); - exit(1); - } - }); - // Notify of startup via HTTP if let Some(startup_notification_url) = args.startup_notification_url { tracing::debug!("Startup notification via HTTP POST to {startup_notification_url}"); @@ -427,11 +412,20 @@ async fn main_cli() -> Result<()> { tracing::debug!("Created startup notification file at {startup_notification_file_path:?}"); } + let ret = axum::Server::bind(&args.listen) + .serve(app.into_make_service()) + .with_graceful_shutdown(async move { + shutdown_receiver.await.ok(); + tracing::info!("Shutting down"); + })?; + // Notify diagnostics endpoint if let Some(diagnostic_endpoint) = diagnostic_endpoint { state.metrics.send(diagnostic_endpoint).await; } + ret?; + Ok(()) } From 1bb6c86f5d648107eec8554be28a51d6dcb1c2fd Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 17 May 2024 15:49:20 -0300 Subject: [PATCH 2/2] Remove unused import --- magic-nix-cache/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index 1a0d370..e0af249 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -26,7 +26,6 @@ use std::io::Write; use std::net::SocketAddr; use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; -use std::process::exit; use std::sync::Arc; use ::attic::nix_store::NixStore; @@ -417,7 +416,8 @@ async fn main_cli() -> Result<()> { .with_graceful_shutdown(async move { shutdown_receiver.await.ok(); tracing::info!("Shutting down"); - })?; + }) + .await; // Notify diagnostics endpoint if let Some(diagnostic_endpoint) = diagnostic_endpoint {