qmemman: make memory request handling more defensive

If getting memory for new VM fails for any reason, make sure that global
lock will be released. Otherwise qmemman will stop functioning at all.

QubesOS/qubes-issues#1636
This commit is contained in:
Marek Marczykowski-Górecki 2016-02-22 17:56:43 +01:00
parent 5546d679c0
commit 0121cb2fd4
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -175,6 +175,7 @@ class QMemmanReqHandler(SocketServer.BaseRequestHandler):
self.log = logging.getLogger('qmemman.daemon.reqhandler') self.log = logging.getLogger('qmemman.daemon.reqhandler')
got_lock = False got_lock = False
try:
# self.request is the TCP socket connected to the client # self.request is the TCP socket connected to the client
while True: while True:
self.data = self.request.recv(1024).strip() self.data = self.request.recv(1024).strip()
@ -184,8 +185,6 @@ class QMemmanReqHandler(SocketServer.BaseRequestHandler):
if got_lock: if got_lock:
global force_refresh_domain_list global force_refresh_domain_list
force_refresh_domain_list = True force_refresh_domain_list = True
global_lock.release()
self.log.debug('global_lock released')
return return
# XXX something is wrong here: return without release? # XXX something is wrong here: return without release?
@ -204,8 +203,13 @@ class QMemmanReqHandler(SocketServer.BaseRequestHandler):
resp = "FAIL\n" resp = "FAIL\n"
self.log.debug('resp={!r}'.format(resp)) self.log.debug('resp={!r}'.format(resp))
self.request.send(resp) self.request.send(resp)
except BaseException as e:
# XXX no release of lock? self.log.exception(
"exception while handling request: {!r}".format(e))
finally:
if got_lock:
global_lock.release()
self.log.debug('global_lock released')
def start_server(server): def start_server(server):