Skip to content

Commit

Permalink
Drop references to libvirt objects when undefining the domain
Browse files Browse the repository at this point in the history
Normally it wouldn't matter because dropping reference to
VirDomainWrapper would do. But if there is an exception that happened
during libvirt call (like createWithFlags), the traceback attached to
the exception would keep reference to VirDomainWrapper object,
preventing closing libvirt connection.

During normal runtime it isn't huge problem, as those exceptions are
discarded soon after anyway. But during tests, they are all collected,
and that results in leaking a lot of libvirt connection objects, and as
a consequence open file descriptors.

QubesOS/qubes-issues#
  • Loading branch information
marmarek committed Oct 7, 2024
1 parent 4643a8d commit abbcf6e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions qubes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def _reconnect_if_dead(self):
self._vm = self._connection._conn.lookupByUUID(self._vm.UUID())
return is_dead

def close(self):
self._vm = None
self._connection = None

def __getattr__(self, attrname):
attr = getattr(self._vm, attrname)
if not isinstance(attr, collections.abc.Callable):
Expand Down
1 change: 1 addition & 0 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,7 @@ def libvirt_undefine(self):
# already undefined
pass
if self._libvirt_domain is not None:
self._libvirt_domain.close()
self._libvirt_domain = None

#
Expand Down

0 comments on commit abbcf6e

Please sign in to comment.