Fix credential_db schema conflict and add resilience

credential_sniffer and credential_db both wrote to the same credentials.db
with different schemas; credential_db's executescript failed when creating
the crack_status index on an existing table that lacked that column.

Fix: split credential_db's schema init into table DDL + migration + indexes
so missing columns are added before index creation runs. Migration also
handles any future schema drift.

state.py: add 30s timeout + busy_timeout PRAGMA to write connection so
concurrent subprocess writes stop failing with 'database is locked'.

capture_bus.py: reconnect on ENETDOWN instead of aborting the capture
loop — mac_manager temporarily brings the interface down during MAC
rotation which was silently killing all packet capture.
This commit is contained in:
Cobra
2026-04-07 12:19:56 -04:00
parent 1f0e3ee79a
commit a8b81f38c9
3 changed files with 54 additions and 15 deletions
+15 -3
View File
@@ -170,9 +170,21 @@ class CaptureBus:
except socket.timeout:
continue
except OSError as e:
if self._running:
logger.error("Socket read error: %s", e)
break
if not self._running:
break
logger.warning("Socket read error: %s — reconnecting in 3s", e)
try:
self._sock.close()
except Exception:
pass
time.sleep(3)
try:
self._sock = self._open_socket()
logger.info("CaptureBus reconnected on %s", self.interface)
except OSError as e2:
logger.error("CaptureBus reconnect failed: %s", e2)
time.sleep(10)
continue
ts = time.time()
self._total_packets += 1
+2 -1
View File
@@ -139,9 +139,10 @@ class StateManager:
def _get_write_conn(self) -> sqlite3.Connection:
if self._write_conn is None:
self._write_conn = sqlite3.connect(self._db_path, check_same_thread=False)
self._write_conn = sqlite3.connect(self._db_path, check_same_thread=False, timeout=30)
self._write_conn.execute("PRAGMA journal_mode=WAL")
self._write_conn.execute("PRAGMA synchronous=NORMAL")
self._write_conn.execute("PRAGMA busy_timeout=30000")
return self._write_conn
# ------------------------------------------------------------------