From 957674fca45a66a40c5b3dc74dc4e3cbf3ebc4e9 Mon Sep 17 00:00:00 2001 From: M1 Date: Wed, 18 Mar 2026 14:29:37 +0400 Subject: [PATCH] fix: clear in-flight after post_result to prevent double-pings, revert poll to 50ms --- apps/monitor/src/main.rs | 2 +- apps/monitor/src/runner.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/monitor/src/main.rs b/apps/monitor/src/main.rs index 39cf5c0..05ac45a 100644 --- a/apps/monitor/src/main.rs +++ b/apps/monitor/src/main.rs @@ -41,6 +41,6 @@ async fn main() -> Result<()> { Ok(n) => { if n > 0 { info!("Spawned {n} checks"); } }, Err(e) => error!("Check cycle failed: {e}"), } - sleep(Duration::from_millis(500)).await; + sleep(Duration::from_millis(50)).await; } } diff --git a/apps/monitor/src/runner.rs b/apps/monitor/src/runner.rs index e5edcd7..d7ef573 100644 --- a/apps/monitor/src/runner.rs +++ b/apps/monitor/src/runner.rs @@ -61,11 +61,12 @@ pub async fn fetch_and_run( meta: None, }, }; - // Remove from in-flight before posting so a fast next cycle can pick it up - in_flight.lock().await.remove(&monitor.id); + // Post result first, then clear in-flight — this prevents the next + // poll from picking up the monitor again before the ping is persisted. if let Err(e) = post_result(&client, &coordinator_url, &token, result).await { warn!("Failed to post result for {}: {e}", monitor.id); } + in_flight.lock().await.remove(&monitor.id); }); }