Skip to content

Commit

Permalink
fix bug in websocket close callback
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniszewski committed Oct 31, 2019
1 parent 531ea6f commit 76f8ac9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pytest-cov==2.8.1
pytest-mock==1.11.2
pytest==5.2.2
six==1.12.0 # via packaging
typing-extensions==3.7.4 # via aiohttp
typing-extensions==3.7.4.1 # via aiohttp
wcwidth==0.1.7 # via pytest
yarl==1.3.0 # via aiohttp
zipp==0.6.0 # via importlib-metadata
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ujson==1.35 # via sanic
urllib3==1.25.6 # via kubernetes, requests
uvloop==0.13.0 # via sanic
websocket-client==0.56.0 # via kubernetes
websockets==7.0
websockets==8.0.2

# The following packages are considered to be unsafe in a requirements file:
# setuptools==41.4.0 # via kubernetes, protobuf
# setuptools==41.6.0 # via kubernetes, protobuf
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'sanic>=0.8.0',
'prometheus-client',
'structlog',
'websockets==7.0', # fixme: temporarily pin
'websockets',
'synse-grpc==3.0.0a4', # fixme: for alpha v3 testing; update to stable v3 release
],
zip_safe=False,
Expand Down
7 changes: 5 additions & 2 deletions synse_server/api/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ def __init__(self, ws):

# When the websocket is cancelled or terminates, ensure that the MessageHandler
# associated with that websocket is stopped and cleaned up.
if ws.close_connection_task is not None:
#
# As of websockets==8.0.0, the `close_connection_task` member will not exit until
# the client is connected. Check both that the attribute exists and that it is not
# None before attempting to add a done callback to the task.
if hasattr(ws, 'close_connection_task') and ws.close_connection_task is not None:
ws.close_connection_task.add_done_callback(self.stop)

# todo - if this don't work, just use threads.
self.tasks = []

async def run(self):
Expand Down

0 comments on commit 76f8ac9

Please sign in to comment.