Fix websocket error when closing the server

Fix #634
This commit is contained in:
Julien Duponchelle 2016-08-19 11:20:56 +02:00
parent f0fad5289c
commit fa76b89731
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
4 changed files with 7 additions and 5 deletions

View File

@ -299,6 +299,7 @@ class Compute:
# https://www.python.org/dev/peps/pep-0492/ # https://www.python.org/dev/peps/pep-0492/
# that why we wrap the answer # that why we wrap the answer
class StreamResponse: class StreamResponse:
def __init__(self, response): def __init__(self, response):
self._response = response self._response = response
@ -350,7 +351,11 @@ class Compute:
""" """
self._ws = yield from self._session().ws_connect(self._getUrl("/notifications/ws")) self._ws = yield from self._session().ws_connect(self._getUrl("/notifications/ws"))
while True: while True:
try:
response = yield from self._ws.receive() response = yield from self._ws.receive()
except aiohttp.errors.WSServerHandshakeError:
self._ws = None
return
if response.tp == aiohttp.MsgType.closed or response.tp == aiohttp.MsgType.error: if response.tp == aiohttp.MsgType.closed or response.tp == aiohttp.MsgType.error:
self._connected = False self._connected = False
break break

View File

@ -165,7 +165,7 @@ class Link:
@property @property
def nodes(self): def nodes(self):
return [ node['node'] for node in self._nodes ] return [node['node'] for node in self._nodes]
@property @property
def capturing(self): def capturing(self):

View File

@ -127,4 +127,3 @@ def wait_for_named_pipe_creation(pipe_path, timeout=60):
else: else:
return return
raise asyncio.TimeoutError() raise asyncio.TimeoutError()

View File

@ -67,5 +67,3 @@ def test_wait_for_process_termination(loop):
exec = wait_for_process_termination(process, timeout=0.5) exec = wait_for_process_termination(process, timeout=0.5)
with pytest.raises(asyncio.TimeoutError): with pytest.raises(asyncio.TimeoutError):
loop.run_until_complete(asyncio.async(exec)) loop.run_until_complete(asyncio.async(exec))