From ddda5150f290c3ca0f7c4ea84f99f9f6d264353c Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Wed, 15 Jan 2025 13:59:07 -0500 Subject: [PATCH] Fix issue around host garbage collection As identified in #334, we can get into a state during garbage collection where a Host instance's _session attribute is missing. However, the del method calls close, which expects that attribute to be in place. In this change, we add a couple of conditions to the del to gate the close call. fixes #334 --- broker/hosts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/broker/hosts.py b/broker/hosts.py index bbc0095..e651b54 100644 --- a/broker/hosts.py +++ b/broker/hosts.py @@ -74,8 +74,8 @@ def __init__(self, **kwargs): def __del__(self): """Try to close the connection on garbage collection of the host instance.""" - self.close() - # object.__del__ DNE, so I don't have to call it here. + if hasattr(self, "_session") and self._session is not None: + self.close() # If host inherits from a different class with __del__, it should get called through super @property