From ec1f064b09c201f5c729c29f8116bc461380f107 Mon Sep 17 00:00:00 2001 From: Raf Geens Date: Tue, 4 May 2021 12:20:33 +0000 Subject: [PATCH] [FIX] hw_drivers: Start iot_devices thread after registering it This commit was originally part of a larger commit related to an Ingenico double connection deadlock bugfix in V13, but in V14 most of the related code has moved to enterprise. When a driver thread is running, calling `disconnect` on it will delete it from iot_devices. If the driver thread gets added to iot_devices in the Interface thread after starting it, this means there is a tiny window of time where `disconnect` could be called and the thread wouldn't be in iot_devices yet, resulting in an exception. This change puts the driver thread in iot_devices before starting it, avoiding that scenario and the need to check in `disconnect` for that happening. X-original-commit: 6c24d30c3910e67ed751327d1554e2e8cf5e958b --- addons/hw_drivers/interface.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/hw_drivers/interface.py b/addons/hw_drivers/interface.py index 28ad1a55e0a..56952d1e084 100644 --- a/addons/hw_drivers/interface.py +++ b/addons/hw_drivers/interface.py @@ -51,8 +51,12 @@ class Interface(Thread, metaclass=InterfaceMetaClass): _logger.info('Device %s is now connected', identifier) d = driver(identifier, devices[identifier]) d.daemon = True - d.start() iot_devices[identifier] = d + # Start the thread after creating the iot_devices entry so the + # thread can assume the iot_devices entry will exist while it's + # running, at least until the `disconnect` above gets triggered + # when `removed` is not empty. + d.start() break def get_devices(self):