fix: guard _looked_up_icaos popitem against concurrent clear(); add eviction tests

contextlib.suppress(KeyError) around popitem prevents a crash in the SBS
parser thread if stop_adsb() calls clear() concurrently between the len()
check and the popitem call.

Two unit tests verify FIFO eviction semantics and duplicate-key no-op.
This commit is contained in:
James Smith
2026-05-19 17:47:21 +01:00
parent a5f92ded37
commit dbe2003d75
2 changed files with 95 additions and 58 deletions
+2 -1
View File
@@ -731,7 +731,8 @@ def parse_sbs_stream(service_addr):
# Look up aircraft type from database (once per ICAO)
if icao not in _looked_up_icaos:
if len(_looked_up_icaos) >= _ICAO_CACHE_MAX:
_looked_up_icaos.popitem(last=False)
with contextlib.suppress(KeyError):
_looked_up_icaos.popitem(last=False)
_looked_up_icaos[icao] = None
db_info = aircraft_db.lookup(icao)
if db_info: