Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Websocket client/server inconsistencies #938

guettli opened this Issue · 2 comments

3 participants


In exceptions get sometimes swallowed.

After modifying this line, I could find the root of the problem:

diff --git a/tornado/ b/tornado/
index b1e82b0..83b9d88 100644
--- a/tornado/
+++ b/tornado/
@@ -300,7 +300,7 @@ def wrap(fn):
             if top is None:
                     ret = fn(*args, **kwargs)
-                except:
+                except IOError:
                     exc = sys.exc_info()
                     top = contexts[1]

Of course this is just a small hack, which can't make it into the real code.

Here is the exception which happens inside a websocket client:

Exception in callback <functools.partial object at 0x1469ec0>
Traceback (most recent call last):
  File "/home/modwork_eins_dmes/src/tornado/tornado/", line 461, in _run_callback
  File "/home/modwork_eins_dmes/src/tornado/tornado/", line 302, in wrapped
    ret = fn(*args, **kwargs)
  File "/home/modwork_eins_dmes/src/tornado/tornado/", line 353, in wrapper
  File "/home/modwork_eins_dmes/src/tornado/tornado/", line 302, in wrapped
    ret = fn(*args, **kwargs)
  File "/home/modwork_eins_dmes/src/tornado/tornado/", line 719, in _on_frame_data
    self._handle_message(opcode, data)
  File "/home/modwork_eins_dmes/src/tornado/tornado/", line 735, in _handle_message
  File "/home/modwork_eins_dmes/src/tornado/tornado/", line 325, in wrapper
    self.request.path, exc_info=True)
  File "/home/modwork_eins_dmes/src/tornado/tornado/", line 485, in __getattr__
    request_attr = getattr(self.request, name)
AttributeError: 'HTTPRequest' object has no attribute 'path'

In line 325 request.path gets accessed to create an error message. But the websocket request does not have this attribute. One possible fix would be to use getattr(request, 'path', None) in websocket Line 325.


The exception handling in StackContext is very deliberate - the exceptions caught here should generally be re-raised somewhere else. I wonder why you weren't seeing that here.

The real problem here is that WebSocketProtocol is used for both client and server connections without being explicit about what it needs from its "handler" argument. This needs to be audited and cleaned up so that the protocol knows what it needs instead of relying on the fact that client- and server-side connections both have some attributes in common.

@bdarnell bdarnell added the websocket label

I hit this bug too when implementing a WebSocket client, my callback raised an exception but the _run_callback swallowed the exception because the request object does not have a 'path' attribute. A simple fix would be to not use self.request.path in the exception logger or use 'getattr' to get the request path to avoid the AttributeError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.