of_core is also iterating on a shared dictself.controller.switches that can have insertions without a (reader) lock or shallow copy, it's also vulnerable to RuntimeError dict changed size. In practice, switches likely won't keep being added that frequently, but the issue is there and can crash.
kytos $> from kytos.core.switch import Switch
kytos $> controller.add_new_switch(Switch("1")2022-08-12 10:13:09,155 - INFO [kytos.napps.kytos/of_core] (of_core) execute starting to sleep
kytos $> controller.add_new_switch(Switch("1"))
kytos $> controller.add_new_switch(Switch("2"))
kytos $> controller.add_new_switch(Switch("3"))
kytos $> len(controller.switches)
Out[6]: 6
Exception in thread of_core:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/home/viniarck/repos/kytos/kytos/core/napps/base.py", line 250, in run
self.execute()
File "/home/viniarck/repos/napps/napps/kytos/of_core/main.py", line 61, in execute
for switch in self.controller.switches.values():
RuntimeError: dictionary changed size during iteration
of_core is also iterating on a shared dict
self.controller.switches
that can have insertions without a (reader) lock or shallow copy, it's also vulnerable to RuntimeError dict changed size. In practice, switches likely won't keep being added that frequently, but the issue is there and can crash.