diff --git a/releasenotes/notes/fix-to-close-session-on-dealloc-c3687d4dcb1441b8.yaml b/releasenotes/notes/fix-to-close-session-on-dealloc-c3687d4dcb1441b8.yaml new file mode 100644 index 00000000..df9fbfd5 --- /dev/null +++ b/releasenotes/notes/fix-to-close-session-on-dealloc-c3687d4dcb1441b8.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Tries to terminate authenticated Redfish session at BMC Session Service on + the event of ``Sushy`` object deallocation. This should reduce the chance + of authenticated sessions pool exhaustion at some BMCs. diff --git a/sushy/main.py b/sushy/main.py index 5f9e9fa9..364c147e 100644 --- a/sushy/main.py +++ b/sushy/main.py @@ -110,10 +110,21 @@ class Sushy(base.ResourceBase): super(Sushy, self).__init__( connector or sushy_connector.Connector(base_url, verify=verify), path=self._root_prefix) + self._base_url = base_url self._auth = auth self._auth.set_context(self, self._conn) self._auth.authenticate() + def __del__(self): + if self._auth: + try: + self._auth.close() + + except Exception as ex: + LOG.warning('Ignoring error while closing Redfish session ' + 'with %s: %s', self._base_url, ex) + self._auth = None + def _parse_attributes(self): super(Sushy, self)._parse_attributes() self.redfish_version = self.json.get('RedfishVersion')