Skip to content

fix: avoid division by zero when logging watch load rate - #4289

Merged
dgtlmoon merged 1 commit into
dgtlmoon:masterfrom
snowyukitty:fix/zero-elapsed-watch-load-rate
Aug 16, 2026
Merged

dgtlmoon merged 1 commit into
dgtlmoon:masterfrom
snowyukitty:fix/zero-elapsed-watch-load-rate

Conversation

@snowyukitty

Copy link
Copy Markdown
Contributor

Summary

  • Measure watch-loading durations with time.perf_counter().
  • Avoid dividing by zero when the clock reports a non-positive elapsed duration.
  • Add a deterministic regression test for an empty datastore completing within one clock tick.

Root cause

load_all_watches() used time.time() and unconditionally formatted loaded / elapsed in both completion log paths. A fast load can receive identical clock readings, making elapsed == 0.0; an empty datastore then aborts startup with ZeroDivisionError while trying to log 0 / 0.0.

This was reproduced on Windows, where the wall clock has lower resolution, but the guard is platform-independent. The regression test replaces only this module's clock reference with constant readings, fails on master, and passes with this fix.

Testing

  • Regression test before the fix: fails with ZeroDivisionError at file_saving_datastore.py:330.
  • pytest -q changedetectionio/tests/unit/test_file_saving_datastore.py — 1 passed.
  • pytest -q changedetectionio/tests/unit/ — 210 passed, 30 subtests passed.
  • ruff check . --select E9,F63,F7,F82,INT.
  • ruff check changedetectionio/tests/unit/test_file_saving_datastore.py.
  • git diff --check.

@dgtlmoon
dgtlmoon merged commit 21f19b2 into dgtlmoon:master Aug 16, 2026
8 checks passed
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.

2 participants