Skip to content

Commit f322f8d

Browse files
committed
VirDomainWrapper: avoid keeping libvirt object ref in locals
Complementary to the previous commit, avoid keeping keeping libvirt object (function) reference in locals, which become closure for the wrapper. Do getattr (again) when the actual call is made. The primary reason for this change is to avoid leaking objects during tests, but also this fixes a rare failure more - if external caller would cache returned function, it wouldn't work after reconnection. For example: # libvirt_domain is VirDomainWrapper() object >>> func = libvirt_domain.pause >>> func() >>> func() If reconnection happens during the first call (or between calls), the second call would use stale function reference.
1 parent abbcf6e commit f322f8d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

qubes/app.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ def __getattr__(self, attrname):
104104
@functools.wraps(attr)
105105
def wrapper(*args, **kwargs):
106106
try:
107-
return attr(*args, **kwargs)
107+
return getattr(self._vm, attrname)(*args, **kwargs)
108108
except libvirt.libvirtError:
109109
if self._reconnect_if_dead():
110110
return getattr(self._vm, attrname)(*args, **kwargs)
111111
raise
112112

113+
del wrapper.__wrapped__
114+
del attr
113115
return wrapper
114116

115117

0 commit comments

Comments
 (0)