From f97a965311af6f71bfbb843c2ea551ffdf4225db Mon Sep 17 00:00:00 2001 From: Joaquin Madrid Belando Date: Sun, 5 Apr 2026 23:25:33 +0200 Subject: [PATCH 1/2] Fix: dictionary changed size during iteration - usar list(BRIDGES) en todas las iteraciones --- bridge_master.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index b30cc5a..d557435 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -302,7 +302,7 @@ def reset_static_tg(tg,ts,_tmout,system): def reset_all_reflector_system(_tmout,system): for system in CONFIG['SYSTEMS']: - for bridge in BRIDGES: + for bridge in list(BRIDGES): if bridge[0:1] == '#': for bridgesystem in BRIDGES[bridge]: bridgetemp = deque() @@ -1810,7 +1810,7 @@ def options_config(): if int(_options['DEFAULT_UA_TIMER']) != CONFIG['SYSTEMS'][_system]['DEFAULT_UA_TIMER']: logger.debug('(OPTIONS) %s Updating DEFAULT_UA_TIMER for existing bridges.',_system) remove_bridge_system(_system) - for _bridge in BRIDGES: + for _bridge in list(BRIDGES): ts1 = False ts2 = False for i,e in enumerate(BRIDGES[_bridge]): @@ -2482,7 +2482,7 @@ class routerOBP(OPENBRIDGE): make_stat_bridge(_dst_id) _sysIgnore = deque() - for _bridge in BRIDGES: + for _bridge in list(BRIDGES): for _system in BRIDGES[_bridge]: if _system['SYSTEM'] == self._system and _system['TGID'] == _dst_id and _system['TS'] == _slot and _system['ACTIVE'] == True: @@ -3400,7 +3400,7 @@ class routerHBP(HBSYSTEM): # Now, run the general routing loop for all other bridges to handle cross-connections. # We skip the one we just processed to avoid duplicate work. - for _bridge in BRIDGES: + for _bridge in list(BRIDGES): if _bridge == _current_bridge_key: continue for _system in BRIDGES[_bridge]: @@ -3429,7 +3429,7 @@ class routerHBP(HBSYSTEM): # # Iterate the rules dictionary - for _bridge in BRIDGES: + for _bridge in list(BRIDGES): if (_bridge[0:1] == '#') and (_int_dst_id != 9): continue for _system in BRIDGES[_bridge]: From f49b9b0cbf4a607ef32335e03a994eea86d7c90c Mon Sep 17 00:00:00 2001 From: Joaquin Madrid Belando Date: Mon, 6 Apr 2026 00:10:45 +0200 Subject: [PATCH 2/2] Fix: proteger acceso a BRIDGES[_bridge] con KeyError guard tras list(BRIDGES) --- bridge_master.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bridge_master.py b/bridge_master.py index d557435..a2edc8e 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -337,6 +337,8 @@ def remove_bridge_system(system): _bridgestemp = {} _bridgetemp = {} for _bridge in list(BRIDGES): + if _bridge not in BRIDGES: + continue for _bridgesystem in BRIDGES[_bridge]: if _bridgesystem['SYSTEM'] != system: if _bridge not in _bridgestemp: @@ -352,6 +354,8 @@ def remove_bridge_system(system): def deactivate_all_dynamic_bridges(system_name): """Desactiva todos los bridges dinámicos (no estáticos, no reflectores) de un sistema.""" for _bridge in list(BRIDGES): + if _bridge not in BRIDGES: + continue if _bridge[0:1] == '#': # Saltar reflectores continue for _sys_entry in BRIDGES[_bridge]: @@ -373,6 +377,8 @@ def rule_timer_loop(): _debug_msgs = [] for _bridge in list(BRIDGES): + if _bridge not in BRIDGES: + continue _bridge_used = False ### MODIFIED: Detect special TGIDs (9990-9999) to exclude them from infinite timer logic @@ -471,6 +477,8 @@ def statTrimmer(): logger.debug('(ROUTER) STAT trimmer loop started') _remove_bridges = deque() for _bridge in list(BRIDGES): + if _bridge not in BRIDGES: + continue _bridge_stat = False _in_use = False for _system in BRIDGES[_bridge]: @@ -531,6 +539,8 @@ def bridgeDebug(): #_setbridge = str(times[bridgetmout]) if CONFIG['SYSTEMS'][system]['MODE'] == 'MASTER': for _bridge in set(times.values()): + if _bridge not in BRIDGES: + continue logger.warning('(BRIDGEDEBUG) deactivating system: %s for bridge: %s',system,_bridge) bridgetemp = deque() for bridgesystem in BRIDGES[_bridge]: @@ -1811,6 +1821,8 @@ def options_config(): logger.debug('(OPTIONS) %s Updating DEFAULT_UA_TIMER for existing bridges.',_system) remove_bridge_system(_system) for _bridge in list(BRIDGES): + if _bridge not in BRIDGES: + continue ts1 = False ts2 = False for i,e in enumerate(BRIDGES[_bridge]): @@ -2483,6 +2495,8 @@ class routerOBP(OPENBRIDGE): _sysIgnore = deque() for _bridge in list(BRIDGES): + if _bridge not in BRIDGES: + continue for _system in BRIDGES[_bridge]: if _system['SYSTEM'] == self._system and _system['TGID'] == _dst_id and _system['TS'] == _slot and _system['ACTIVE'] == True: @@ -3401,6 +3415,8 @@ class routerHBP(HBSYSTEM): # Now, run the general routing loop for all other bridges to handle cross-connections. # We skip the one we just processed to avoid duplicate work. for _bridge in list(BRIDGES): + if _bridge not in BRIDGES: + continue if _bridge == _current_bridge_key: continue for _system in BRIDGES[_bridge]: @@ -3430,6 +3446,8 @@ class routerHBP(HBSYSTEM): # Iterate the rules dictionary for _bridge in list(BRIDGES): + if _bridge not in BRIDGES: + continue if (_bridge[0:1] == '#') and (_int_dst_id != 9): continue for _system in BRIDGES[_bridge]: