Properly catch websocket CancelledError in websocket handler in Python 3.7

(cherry picked from commit 4ee2e57ec8474cf7c9a4f018de97926d8899f7cb)
This commit is contained in:
Ashley Sommer 2022-05-24 05:47:05 +10:00
parent c4da66bf1f
commit 698a359808

View File

@ -1004,10 +1004,10 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
cancelled = False cancelled = False
try: try:
await fut await fut
except Exception as e:
self.error_handler.log(request, e)
except (CancelledError, ConnectionClosed): except (CancelledError, ConnectionClosed):
cancelled = True cancelled = True
except Exception as e:
self.error_handler.log(request, e)
finally: finally:
self.websocket_tasks.remove(fut) self.websocket_tasks.remove(fut)
if cancelled: if cancelled: