esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Scheduler stops running 0ms intervals after 99.4 days #1663

Open mmorrisontx opened 3 years ago

mmorrisontx commented 3 years ago

Operating environment/Installation (Hass.io/Docker/pip/etc.):

Docker

ESP (ESP32/ESP8266, Board/Sonoff):

Various ESP8266 + ESP32

ESPHome version (latest production, beta, dev branch)

ESPHome version 1.16.0-dev compiled on Aug 20 2020, 13:55:01

Affected component:

Scheduler

Description of problem: All 60 of my esphome light switches stopped "switching" today, after a smooth 99 days of uptime. Suspiciously, this is exactly 2x the millis() rollover.

After some investigation, it appears that next_execution_major() never goes past 0 for 0ms intervals, it only works for timeouts.

The next_execution major is never bumpes here: https://github.com/esphome/esphome/blob/7ff3f752e23b0c11aa2123209d7b2e296cbfdf63/esphome/core/scheduler.h#L42 , because next_exec < this->last_execution is never true, because next_execution() == this->last_execution for all intervals (because the timeout field is always 0).

And the next_execution major is never bumped here: https://github.com/esphome/esphome/blob/7ff3f752e23b0c11aa2123209d7b2e296cbfdf63/esphome/core/scheduler.cpp#L175 , because it only applies if interval != 0.

The scheduler skips all executions when the major is off by over 1 (https://github.com/esphome/esphome/blob/7ff3f752e23b0c11aa2123209d7b2e296cbfdf63/esphome/core/scheduler.cpp#L140), thus why it lasts 2x the rollover rather than just one.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.