Skip to content

Fix: avoid connection-error spam from background refresh after system sleep - #292

Open
px-pole wants to merge 2 commits into
WillyJL:mainfrom
px-pole:fix/bg-refresh-after-sleep
Open

Fix: avoid connection-error spam from background refresh after system sleep#292
px-pole wants to merge 2 commits into
WillyJL:mainfrom
px-pole:fix/bg-refresh-after-sleep

Conversation

@px-pole

@px-pole px-pole commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Problem

The background (tray) mode refresh/notification-check timers in `modules/gui.py` are wall-clock based (`time.time()`). When the PC goes to sleep, the wall clock keeps advancing (RTC), so the scheduled timer is already overdue the moment the system resumes. The app then immediately tries to refresh, before the network adapter/DNS/DHCP has reconnected, causing a batch of connection error popups that pile up in the popup stack.

Fix

  • Detect a sleep/resume gap by comparing wall-clock delta vs monotonic-clock delta each frame; when the gap is large (>10s), push any pending `bg_mode_timer`/`bg_mode_notifs_timer` forward instead of letting them fire instantly on wake.
  • Add `utils.is_network_available()`, a cheap DNS-based connectivity check, and use it to silently defer (retry every 15s) the scheduled background refresh/notif check until the network is actually reachable, instead of surfacing a connection error popup.

Testing

Manually verified the background loop logic; suspended/resumed a test machine and confirmed the scheduled refresh no longer fires until DNS resolution succeeds again.

… sleep

Background scheduled refresh/notif-check timers are wall-clock based, so
after the PC wakes from sleep the overdue timer fires immediately, before
the network is back up, producing a pile of connection error popups.

- Detect a sleep/resume gap (wall clock jumping ahead of monotonic clock)
  and push pending bg timers forward instead of firing them right away.
- Add utils.is_network_available() and use it to silently defer the
  scheduled bg refresh/notif check (retry every 15s) until the network is
  reachable, instead of surfacing a connection error popup.
Copilot AI lite review requested due to automatic review settings August 26, 2026 11:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There is an unused import in modules/gui.py and the new synchronous DNS probe can block the GUI main loop during DNS/network outages.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adjusts the tray/background refresh loop to avoid spamming connection-error popups immediately after system resume (when timers are overdue but networking/DNS may not be ready yet).

Changes:

  • Add utils.is_network_available() to gate background refresh/notif checks until connectivity is present.
  • Detect suspend/resume gaps by comparing wall-clock vs monotonic deltas and push background timers forward on wake.
  • Defer scheduled background refresh/notif tasks by rescheduling short retries when the network check fails.
File summaries
File Description
modules/utils.py Adds a synchronous network-availability probe used to defer background tasks.
modules/gui.py Adds sleep/resume detection and uses the network probe to delay tray-mode refresh/notif checks.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread modules/gui.py
Comment thread modules/utils.py
…cking

- Remove unused `socket` import from modules/gui.py.
- modules/utils.py: is_network_available() no longer calls
  socket.getaddrinfo() synchronously on the caller's thread (which could
  block the GUI main loop for seconds during DNS/network outages).
  It now returns a cached last-known state and refreshes it via a
  daemon background thread, so the main loop never blocks.
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