Skip to content

fix(alerts): treat an outage start newer than now as zero elapsed - #101

Open
agessaman wants to merge 1 commit into
observer-firmware-devfrom
fix/alert-duration-underflow
Open

agessaman wants to merge 1 commit into
observer-firmware-devfrom
fix/alert-duration-underflow

Conversation

@agessaman

Copy link
Copy Markdown
Owner

Problem

A ThinkNode M7 on the current dev release sent "MQTT slot 5 (analyzer-us) down 1193h2m" followed in the same minute by "recovered after 0m". 1193h2m is 2^32 ms.

The alerter takes now on the main loop, then reads the outage start, which the esp-mqtt task (or the WiFi event task) stamps with its own millis(). A disconnect landing in between leaves the start newer than now, the unsigned subtraction wraps, and the result passes the "down longer than N minutes" threshold at once.

Fix

AlertFaultPolicy::downDurationMs treats a start up to 60 s newer than now as zero elapsed. The MQTT slot alerts and the WiFi/Ethernet alert both go through it, on repeater and room server.

Side effect: an outage whose age is in the last 60 s before the 49.7-day wrap reads as zero for that minute.

Testing

  • pio test -e native -f test_alert_fault_policy: 26 of 26 pass, including two new cases (start stamped after now, and the same across the millis() rollover).
  • Not built for or run on a device.

The outage start is stamped by the esp-mqtt or WiFi event task, so it can be
a few ms newer than the main loop's now. The unsigned subtraction then
wrapped to ~2^32 ms, passed the threshold at once, and sent
"down 1193h2m" for a blip that recovered seconds later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant