From ae82a770db519323018abd29a690764e9aca3679 Mon Sep 17 00:00:00 2001 From: Andrew Wason Date: Fri, 4 Aug 2023 11:43:00 -0400 Subject: [PATCH] Handle write_message raising WebSocketClosedError. Also fix indentation error in htmlfile.py --- sockjs/tornado/transports/htmlfile.py | 2 +- sockjs/tornado/transports/websocket.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sockjs/tornado/transports/htmlfile.py b/sockjs/tornado/transports/htmlfile.py index 8d7fef3..258475f 100644 --- a/sockjs/tornado/transports/htmlfile.py +++ b/sockjs/tornado/transports/htmlfile.py @@ -65,7 +65,7 @@ def get(self, session_id): return if CALLBACK_RE.search(callback): - self.write('invalid "callback" parameter') + self.write('invalid "callback" parameter') self.set_status(500) self.finish() return diff --git a/sockjs/tornado/transports/websocket.py b/sockjs/tornado/transports/websocket.py index 287b18f..272c50c 100644 --- a/sockjs/tornado/transports/websocket.py +++ b/sockjs/tornado/transports/websocket.py @@ -87,7 +87,7 @@ def send_pack(self, message, binary=False): # Send message try: self.write_message(message, binary) - except IOError: + except (IOError, websocket.WebSocketClosedError): self.server.io_loop.add_callback(self.on_close) def session_closed(self):