server: guard against None snapshots crashing the accept loop

If extract_all() returns None (Dashboard init failure), appending it to
store["records"] would cause _accept_loop to crash with AttributeError on
the next client connection.  Since only OSError was caught, the thread
died permanently — no further clients could join push_clients, so live
broadcasts reached nobody.

- collect.py: skip None snapshots instead of appending them
- network.py: filter None records in _accept_loop; catch all exceptions
  during history send (not just OSError) so the thread survives
- storage_helpers.py: filter None records when loading from disk

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-30 00:42:31 +02:00
co-authored by Claude Sonnet 4.6
parent dfd5ef7f56
commit b75c4fe411
3 changed files with 17 additions and 8 deletions
+10 -4
View File
@@ -24,15 +24,17 @@ def _accept_loop(
preloaded = store_ref.get("preloaded", [])
if preloaded:
seen_ts = {r.get("ts") for r in preloaded}
extra = [r for r in in_mem if r.get("ts") not in seen_ts]
records = sorted(preloaded + extra, key=lambda r: r.get("ts", ""))
seen_ts = {r.get("ts") for r in preloaded if r is not None}
extra = [r for r in in_mem if r is not None and r.get("ts") not in seen_ts]
records = sorted(preloaded + extra, key=lambda r: r.get("ts", "") if r is not None else "")
else:
records = in_mem
records = [r for r in in_mem if r is not None]
try:
prev: dict = {}
for record in records:
if record is None:
continue
diff = jay_diff_full(prev, record, combine_upd_add=True)
prev = record
conn.sendall((json.dumps(diff, default=str) + "\n").encode())
@@ -42,6 +44,10 @@ def _accept_loop(
log.debug("Failed to send history to %s", addr)
conn.close()
continue
except Exception:
log.exception("Error sending history to %s — dropping client", addr)
conn.close()
continue
clients.append(conn)
except OSError:
break