From 2f6bfb30bd1430aa139b85fdf4de08920251bdde Mon Sep 17 00:00:00 2001 From: hugues bouvier <33438817+huguesBouvier@users.noreply.github.com> Date: Mon, 29 Nov 2021 11:26:26 -0800 Subject: [PATCH] Add delay between nginx crashes (#5852) Added a delay between nginx restarts to avoid spamming the log file. ## Azure IoT Edge PR checklist: --- edge-modules/api-proxy-module/src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/edge-modules/api-proxy-module/src/main.rs b/edge-modules/api-proxy-module/src/main.rs index bd5cf16c592..4e8190f4f76 100644 --- a/edge-modules/api-proxy-module/src/main.rs +++ b/edge-modules/api-proxy-module/src/main.rs @@ -19,6 +19,7 @@ use tokio::{ process::{Child, Command}, sync::Notify, task::JoinHandle, + time, }; use api_proxy_module::{ @@ -28,6 +29,8 @@ use api_proxy_module::{ }; use shutdown_handle::ShutdownHandle; +const MAX_LOOP_INTERVAL_SECONDS: tokio::time::Duration = tokio::time::Duration::from_secs(1); + #[tokio::main] async fn main() -> Result<()> { env_logger::builder().filter_level(LevelFilter::Info).init(); @@ -188,6 +191,10 @@ pub fn nginx_controller_start( return Ok(()); } } + + // This delay controls how fast the main loop can reconnect once nginx crashed. + // Without this, nginx crashes and restart continuously. Rapidly increasing the size of the logs. + time::sleep(MAX_LOOP_INTERVAL_SECONDS); } } });