fkie / multimaster_fkie

ROS stack with FKIE packages for multi-robot (discovering, synchronizing and management GUI)
BSD 3-Clause "New" or "Revised" License
272 stars 106 forks source link

RuntimeError: dictionary changed size during iteration #150

Closed ProgenitorX closed 3 years ago

ProgenitorX commented 3 years ago

Saw this exception pop up:

Exception in thread Thread-2600: Traceback (most recent call last): File "/home/robo/anaconda3/envs/ros/lib/python3.9/threading.py", line 954, in _bootstrap_inner self.run() File "/home/robo/anaconda3/envs/ros/lib/python3.9/threading.py", line 1266, in run self.function(*self.args, **self.kwargs) File "/home/robo/catkin_ws/src/multimaster/fkie_master_discovery/src/fkie_master_discovery/master_discovery.py", line 803, in checkROSMaster_loop if self.master_monitor.checkState(self._changed): File "/home/robo/catkin_ws/src/multimaster/fkie_master_discovery/src/fkie_master_discovery/master_monitor.py", line 813, in checkState s = self.updateState(clear_cache) File "/home/robo/catkin_ws/src/multimaster/fkie_master_discovery/src/fkie_master_discovery/master_monitor.py", line 601, in updateState self._clearup_cached_logs() File "/home/robo/catkin_ws/src/multimaster/fkie_master_discovery/src/fkie_master_discovery/master_monitor.py", line 624, in _clearup_cached_logs for msg, ts in msgs.items(): RuntimeError: dictionary changed size during iteration

Looks like the code in question deletes dict entries for both self._printed_errors and msgs while iterating through the their items. Fix should be to make a copy of the list of keys in the dict and iterate through the copy grabbing or deleting values as needed from the dict instead.

https://github.com/fkie/multimaster_fkie/blob/48c9434bdb997d32aa49be7d1cc736bb40a41446/fkie_master_discovery/src/fkie_master_discovery/master_monitor.py#L623

atiderko commented 3 years ago

Thank you for reporting!