From aa2c7fd834926af5a1a8469875caefe9f80a79cc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 20 Mar 2026 20:41:08 -1000 Subject: [PATCH] [core] Restore race condition comments in before_loop_tasks_ --- esphome/core/application.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/esphome/core/application.h b/esphome/core/application.h index 7ec3a2a7475..06ff30e81f6 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -845,6 +845,13 @@ inline void ESPHOME_ALWAYS_INLINE Application::before_loop_tasks_(uint32_t loop_ // Process any pending enable_loop requests from ISRs // This must be done before marking in_loop_ = true to avoid race conditions if (this->has_pending_enable_loop_requests_) { + // Clear flag BEFORE processing to avoid race condition + // If ISR sets it during processing, we'll catch it next loop iteration + // This is safe because: + // 1. Each component has its own pending_enable_loop_ flag that we check + // 2. If we can't process a component (wrong state), enable_pending_loops_() + // will set this flag back to true + // 3. Any new ISR requests during processing will set the flag again this->has_pending_enable_loop_requests_ = false; this->enable_pending_loops_(); }