From 19125703981bc6bc78a552625cadf7263cde9d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Humberto=20Di=C3=B3genes?= Date: Wed, 11 Dec 2019 19:32:18 -0300 Subject: [PATCH] Handle exceptions on NApp setup Fix #1000: "Error on a NApp's thread setup may cause locks on kytosd shutdown" --- kytos/core/controller.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kytos/core/controller.py b/kytos/core/controller.py index fccc2d635..c30a684f6 100644 --- a/kytos/core/controller.py +++ b/kytos/core/controller.py @@ -85,7 +85,7 @@ def __init__(self, options=None, loop=None): #: dict: mapping of events and event listeners. #: #: The key of the dict is a KytosEvent (or a string that represent a - #: regex to match agains KytosEvents) and the value is a list of + #: regex to match against KytosEvents) and the value is a list of #: methods that will receive the referenced event self.events_listeners = {'kytos/core.connection.new': [self.new_connection]} @@ -772,11 +772,16 @@ def load_napp(self, username, napp_name): username, napp_name, err) return except FileNotFoundError as err: - msg = "NApp module not found, assuming it's a meta napp: %s" + msg = "NApp module not found, assuming it's a meta-napp: %s" self.log.warning(msg, err.filename) return - napp = napp_module.Main(controller=self) + try: + napp = napp_module.Main(controller=self) + except: # noqa pylint: disable=bare-except + self.log.critical("NApp initialization failed: %s/%s", + username, napp_name, exc_info=True) + return self.napps[(username, napp_name)] = napp