mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
connection: Fix leak if connect fails
Something to do with using sys.exc_info ?
This commit is contained in:
parent
aec781a675
commit
e9980eb41f
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import traceback
|
import traceback
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
@ -885,9 +884,6 @@ class vmmConnection(vmmGObject):
|
|||||||
self.config.set_conn_autoconnect(self.get_uri(), val)
|
self.config.set_conn_autoconnect(self.get_uri(), val)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self.vmm == None:
|
|
||||||
return
|
|
||||||
|
|
||||||
def cleanup(devs):
|
def cleanup(devs):
|
||||||
for dev in devs.values():
|
for dev in devs.values():
|
||||||
dev.cleanup()
|
dev.cleanup()
|
||||||
@ -922,6 +918,7 @@ class vmmConnection(vmmGObject):
|
|||||||
# Do this first, so signals are unregistered before we change state
|
# Do this first, so signals are unregistered before we change state
|
||||||
vmmGObject.cleanup(self)
|
vmmGObject.cleanup(self)
|
||||||
self.close()
|
self.close()
|
||||||
|
self.connectError = None
|
||||||
|
|
||||||
hal_helper = self.get_hal_helper(init=False)
|
hal_helper = self.get_hal_helper(init=False)
|
||||||
if hal_helper:
|
if hal_helper:
|
||||||
@ -1116,59 +1113,57 @@ class vmmConnection(vmmGObject):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _try_open(self):
|
def _try_open(self):
|
||||||
try:
|
flags = 0
|
||||||
flags = 0
|
|
||||||
|
|
||||||
tmp = self._open_dev_conn(self.get_uri())
|
vmm = self._open_dev_conn(self.get_uri())
|
||||||
if tmp:
|
if vmm:
|
||||||
self.vmm = tmp
|
return vmm
|
||||||
return
|
|
||||||
|
|
||||||
if self.readOnly:
|
if self.readOnly:
|
||||||
logging.info("Caller requested read only connection")
|
logging.info("Caller requested read only connection")
|
||||||
flags = libvirt.VIR_CONNECT_RO
|
flags = libvirt.VIR_CONNECT_RO
|
||||||
|
|
||||||
if virtinst.support.support_openauth():
|
if virtinst.support.support_openauth():
|
||||||
self.vmm = libvirt.openAuth(self.get_uri(),
|
vmm = libvirt.openAuth(self.get_uri(),
|
||||||
[[libvirt.VIR_CRED_AUTHNAME,
|
[[libvirt.VIR_CRED_AUTHNAME,
|
||||||
libvirt.VIR_CRED_PASSPHRASE,
|
libvirt.VIR_CRED_PASSPHRASE,
|
||||||
libvirt.VIR_CRED_EXTERNAL],
|
libvirt.VIR_CRED_EXTERNAL],
|
||||||
self._do_creds,
|
self._do_creds, None],
|
||||||
None], flags)
|
flags)
|
||||||
|
else:
|
||||||
|
if flags:
|
||||||
|
vmm = libvirt.openReadOnly(self.get_uri())
|
||||||
else:
|
else:
|
||||||
if flags:
|
vmm = libvirt.open(self.get_uri())
|
||||||
self.vmm = libvirt.openReadOnly(self.get_uri())
|
|
||||||
else:
|
return vmm
|
||||||
self.vmm = libvirt.open(self.get_uri())
|
|
||||||
except:
|
|
||||||
return sys.exc_info()
|
|
||||||
|
|
||||||
def _open_thread(self):
|
def _open_thread(self):
|
||||||
logging.debug("Background 'open connection' thread is running")
|
logging.debug("Background 'open connection' thread is running")
|
||||||
|
|
||||||
done = False
|
while True:
|
||||||
while not done:
|
exc = None
|
||||||
open_error = self._try_open()
|
tb = None
|
||||||
done = True
|
try:
|
||||||
|
self.vmm = self._try_open()
|
||||||
|
except Exception, exc:
|
||||||
|
tb = "".join(traceback.format_exc())
|
||||||
|
|
||||||
if not open_error:
|
if not exc:
|
||||||
self.state = self.STATE_ACTIVE
|
self.state = self.STATE_ACTIVE
|
||||||
continue
|
break
|
||||||
|
|
||||||
self.state = self.STATE_DISCONNECTED
|
self.state = self.STATE_DISCONNECTED
|
||||||
(_type, value, stacktrace) = open_error
|
|
||||||
|
|
||||||
if (_type == libvirt.libvirtError and
|
if (type(exc) == libvirt.libvirtError and
|
||||||
value.get_error_code() == libvirt.VIR_ERR_AUTH_FAILED and
|
exc.get_error_code() == libvirt.VIR_ERR_AUTH_FAILED and
|
||||||
"GSSAPI Error" in value.get_error_message() and
|
"GSSAPI Error" in exc.get_error_message() and
|
||||||
"No credentials cache found" in value.get_error_message()):
|
"No credentials cache found" in exc.get_error_message()):
|
||||||
if self._acquire_tgt():
|
if self._acquire_tgt():
|
||||||
done = False
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
tb = "".join(traceback.format_exception(_type, value, stacktrace))
|
self.connectError = "%s\n\n%s" % (exc, tb)
|
||||||
|
break
|
||||||
self.connectError = "%s\n\n%s" % (str(value), str(tb))
|
|
||||||
|
|
||||||
# We want to kill off this thread asap, so schedule an
|
# We want to kill off this thread asap, so schedule an
|
||||||
# idle event to inform the UI of result
|
# idle event to inform the UI of result
|
||||||
|
Loading…
Reference in New Issue
Block a user