diff --git a/actor/src/udsactor/service.py b/actor/src/udsactor/service.py index 3ae9bc070..1432c2ff2 100644 --- a/actor/src/udsactor/service.py +++ b/actor/src/udsactor/service.py @@ -59,6 +59,7 @@ class CommonService: # pylint: disable=too-many-instance-attributes _isAlive: bool = True _rebootRequested: bool = False _loggedIn = False + _ready = False _cfg: types.ActorConfigurationType _api: rest.UDSServerApi @@ -127,6 +128,8 @@ class CommonService: # pylint: disable=too-many-instance-attributes if not self._isAlive: return + self._ready = False + # First, if postconfig is available, execute it and disable it if self._cfg.post_command: self.execute(self._cfg.post_command, 'postConfig') @@ -143,7 +146,9 @@ class CommonService: # pylint: disable=too-many-instance-attributes counter -= 1 try: self._certificate = self._api.ready(self._cfg.own_token, self._secret, srvInterface.ip, rest.LISTEN_PORT) + self._ready = True except rest.RESTConnectionError as e: + logger.error('Error en ready: %s', e) if not logged: # Only log connection problems ONCE logged = True logger.error('Error connecting with UDS Broker') @@ -272,7 +277,8 @@ class CommonService: # pylint: disable=too-many-instance-attributes if self._loggedIn and self._cfg.own_token: self._loggedIn = False try: - self._api.logout(self._cfg.own_token, '') + if self._ready: + self._api.logout(self._cfg.own_token, '') except Exception as e: logger.error('Error notifying final logout to UDS: %s', e) @@ -358,6 +364,8 @@ class CommonService: # pylint: disable=too-many-instance-attributes # Client notifications def login(self, username: str) -> types.LoginResultInfoType: + if not self._ready: + return types.LoginResultInfoType('', '', 0, 0) result = types.LoginResultInfoType(ip='', hostname='', dead_line=None, max_idle=None) self._loggedIn = True if self._cfg.own_token: @@ -365,6 +373,8 @@ class CommonService: # pylint: disable=too-many-instance-attributes return result def logout(self, username: str) -> None: + if not self._ready: + return self._loggedIn = False if self._cfg.own_token: self._api.logout(self._cfg.own_token, username)