Keep GSMTAP capture alive + server-side liveness logging

The GSMTAP capture thread died silently whenever a single non-SIM or
truncated GSMTAP datagram arrived (read_packet() raises ValueError,
uncaught in the loop, killing the daemon thread while UDP kept
flowing) — matching the "stops listening after a sniffer restart"
symptom.

Fixes:
- GsmtapListener.iter_messages() now catches ValueError/struct.error
  from read_packet(), drops the offending datagram (counted via a new
  `dropped` counter) and keeps listening.
- CaptureManager._capture_loop() guards the DB insert so a transient
  error can't kill the thread; a top-level guard logs
  "ERROR: capture thread stopped on error …" + traceback and clears
  the session so /api/status no longer reports a stuck "active".
- Server now logs capture liveness to stderr: "Capture started", a
  periodic "Capture alive: session=N messages=M bytes=B dropped=D"
  heartbeat (default every 60 s, configurable via log_interval), and
  "Capture stopped" (or "empty session discarded").

Tests: +5 (listener survives non-SIM/short packet, capture loop
survives insert error, logs stop-on-error, heartbeat+stop log).
Stays on 1.22.0 (backend-only).
This commit is contained in:
catarrh committed 2026-08-26 22:21:14 +03:00
1 parent 79acb3773f
commit 51e1b4ae08
3 files changed
+220 -8

No files matched your search

+7
View File
@@ -113,6 +113,13 @@ simtrace2-pysniff-server --capture direct
simtrace2-pysniff-server --capture disabled
```
The server logs its capture liveness to stderr: `Capture started` on
begin, a periodic `Capture alive: session=N messages=M bytes=B dropped=D`
heartbeat, and `Capture stopped` (or `ERROR: capture thread stopped on
error …` if the capture thread died unexpectedly). A mis-framed or
non-SIM GSMTAP datagram is dropped and counted (`dropped`) rather than
silently killing the capture.
The GSMTAP listener also accepts the **sigrok-iso7816-stream** decoder
(https://github.com/anttro/sigrok_iso7816_stream) — an FX2-logic-analyzer
passive SIM sniffer that emits the same GSMTAP-SIM format on UDP 4729. Its