Skip to content

Commit

Permalink
Fix issue around host garbage collection
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JacobCallahan committed Jan 15, 2025
1 parent d0b1192 commit ddda515
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions broker/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ddda515

Please sign in to comment.