api: cleanup already started servers when some later failed

This commit is contained in:
Marek Marczykowski-Górecki 2017-07-12 10:42:47 +02:00
parent d7b968d867
commit e6d5337fa7
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -398,7 +398,18 @@ def create_servers(*args, force=False, loop=None, **kwargs):
shutil.chown(sock.getsockname(), group='qubes')
servers.append(server)
except:
for server in servers:
for sock in server.sockets:
try:
os.unlink(sock.getsockname())
except FileNotFoundError:
pass
server.close()
if servers:
yield from asyncio.wait([
server.wait_closed() for server in servers])
raise
finally:
os.umask(old_umask)