Properly catch websocket CancelledError in websocket handler in Python 3.7

(cherry picked from commit 4ee2e57ec8)
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
try:
await fut
except Exception as e:
self.error_handler.log(request, e)
except (CancelledError, ConnectionClosed):
cancelled = True
except Exception as e:
self.error_handler.log(request, e)
finally:
self.websocket_tasks.remove(fut)
if cancelled: