Skip to content

Websocket client exception on redirect #2405

Open
@willmcgugan

Description

@willmcgugan

When the websocket client receives a redirect status code, rather than a 101, it throws the following exception:

ERROR:tornado.application:Uncaught exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/tornado/http1connection.py", line 237, in _read_message
    delegate.finish()
  File "/usr/local/lib/python3.6/site-packages/tornado/http1connection.py", line 674, in finish
    return self._delegate.finish()
  File "/usr/local/lib/python3.6/site-packages/tornado/simple_httpclient.py", line 500, in finish
    self.client.fetch(new_request, final_callback)
AttributeError: 'NoneType' object has no attribute 'fetch'
ERROR:tornado.application:Exception in callback functools.partial(<function wrap.<locals>.wrapped at 0x107cd9ea0>, <Future finished exception=_QuietException()>)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/tornado/http1connection.py", line 237, in _read_message
    delegate.finish()
  File "/usr/local/lib/python3.6/site-packages/tornado/http1connection.py", line 674, in finish
    return self._delegate.finish()
  File "/usr/local/lib/python3.6/site-packages/tornado/simple_httpclient.py", line 500, in finish
    self.client.fetch(new_request, final_callback)
AttributeError: 'NoneType' object has no attribute 'fetch'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/tornado/ioloop.py", line 759, in _run_callback
    ret = callback()
  File "/usr/local/lib/python3.6/site-packages/tornado/stack_context.py", line 344, in wrapped
    raise_exc_info(exc)
  File "<string>", line 4, in raise_exc_info
  File "/usr/local/lib/python3.6/site-packages/tornado/stack_context.py", line 315, in wrapped
    ret = fn(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/tornado/simple_httpclient.py", line 395, in <lambda>
    lambda f: f.result())
  File "/usr/local/lib/python3.6/site-packages/tornado/gen.py", line 1113, in run
    yielded = self.gen.send(value)
  File "/usr/local/lib/python3.6/site-packages/tornado/http1connection.py", line 237, in _read_message
    delegate.finish()
  File "/usr/local/lib/python3.6/site-packages/tornado/http1connection.py", line 55, in __exit__
    raise _QuietException
tornado.http1connection._QuietException

The Websocket spec has this to say about redirects:

  1. If the status code received from the server is not 101, the
    client handles the response per HTTP [RFC2616] procedures. In
    particular, the client might perform authentication if it
    receives a 401 status code; the server might redirect the client
    using a 3xx status code (but clients are not required to follow
    them), etc. Otherwise, proceed as follows.

So redirects don't appear to a requirement as such, but I don't see any reason why it shouldn't follow them. Websocket redirects have much the same use case as any http redirect. But the client should at the very least be able to handle a non-101 gracefully.

From what I've seen of the code, it looks like Tornado is at least trying to follow the redirect. So I'm hoping it won't be too much effort to fix. With a few pointers I may be able to tackle this myself. Any assistance would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions