🐛 Fix exception not being retrieved on socket error
This should hopefully close #3689 The actual result of writing to the web socket is async and a future, since `write_message` (https://github.com/tornadoweb/tornado/blob/v5.1.1/tornado/websocke.py#L848) returns a future. The error handling inside `send_pack` however so far assumed synchronous behaviour (same for `rawwebsocket.py`). Thus the exception handler there will not trigger if there's an error while writing, and thus the connection will not have `on_close` called. This commit works around this through a `done_callback` on the future, which should hopefully solve it. I say should because even though I did my best in trying to simulate the error scenario, I was never able to trigger even the "retrieved" message, let alone a whole storm of them.
This commit is contained in:
1 parent
b3bc1e75aa
commit
e91fcd6387
3 files changed
+8
-2
No files matched your search
@@ -82,7 +82,7 @@ class RawWebSocketTransport(websocket.SockJSWebSocketHandler, base.BaseTransport
|
||||
# Running in Main Thread
|
||||
# Send message
|
||||
try:
|
||||
self.write_message(message, binary)
|
||||
self.write_message(message, binary).add_done_callback(self.send_complete)
|
||||
except (IOError, WebSocketError):
|
||||
self.server.io_loop.add_callback(self.on_close)
|
||||
else:
|
||||
|
||||
@@ -92,7 +92,7 @@ class WebSocketTransport(websocket.SockJSWebSocketHandler, base.BaseTransportMix
|
||||
# Running in Main Thread
|
||||
# Send message
|
||||
try:
|
||||
self.write_message(message, binary)
|
||||
self.write_message(message, binary).add_done_callback(self.send_complete)
|
||||
except (IOError, WebSocketError):
|
||||
self.server.io_loop.add_callback(self.on_close)
|
||||
else:
|
||||
|
||||
@@ -39,3 +39,9 @@ class SockJSWebSocketHandler(websocket.WebSocketHandler):
|
||||
def abort_connection(self):
|
||||
if self.ws_connection:
|
||||
self.ws_connection._abort()
|
||||
|
||||
def send_complete(self, f=None):
|
||||
try:
|
||||
f.result()
|
||||
except (IOError, websocket.WebSocketError):
|
||||
self.on_close()
|
||||
Reference in new issue
Block a user