Skip to content

simple_httpclient: Timeout after redirect not raised properly #3064

Closed

Description

@wxy8wxy

Hello,
My test codes are below:

import traceback
from tornado import httpclient

def test():
client = httpclient.HTTPClient()
url = "http://www.baidu.com/link?url=7rwodBCaetm-ogDMm0fCdkj-Crje0M21LIWnXbz3XxToow8VmZwXOZaEz1nBMJBKofatc2X8SlFXyNvv5D7HhWgpIB8MDi5R85IYL30OjDmW4URWPW5y4AIwkVKioJSxPPBzWJmmaO11fEEO__BLxIiiT1FcKw8asqqF7h1QupS"
try:
response = client.fetch(url)
print(response)
except:
traceback.print_exc()

if name == "main":
test()

It is suspended after got tornado.simple_httpclient.HTTPTimeoutError. The stack trace is

ERROR:asyncio:Exception in callback _HTTPConnection.finish..() at /home/python3/.miniconda3/lib/python3.8/site-packages/tornado/simple_httpclient.py:664
handle: <Handle _HTTPConnection.finish..() at /home/python3/.miniconda3/lib/python3.8/site-packages/tornado/simple_httpclient.py:664>
Traceback (most recent call last):
File "/home/python3/.miniconda3/lib/python3.8/asyncio/events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "/home/python3/.miniconda3/lib/python3.8/site-packages/tornado/simple_httpclient.py", line 664, in
fut.add_done_callback(lambda f: final_callback(f.result()))
tornado.simple_httpclient.HTTPTimeoutError: Timeout during request

How to fix it?
Thanks!

Python 3.8.5
Tornado 6.1

Try to run it several times to get above error

Activity

  1. Python-37 commented on Sep 18, 2021

    @Python-37
    Contributor

    Did you try to open the URL in your web browser?

  2. changed the title [-]App hang after got HTTPTimeoutError[/-] [+]simple_httpclient: Timeout after redirect not raised properly[/+] on Sep 18, 2021
  3. bdarnell commented on Sep 18, 2021

    @bdarnell
    Member

    This looks like a bug when following redirects: some errors from the second request aren't getting raised correctly. This probably affects asynchronous usage as well as the synchronous HTTPClient, although I'm not certain. There are a couple of workarounds:

    • Install pycurl and run AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient") at the start of your program
    • Pass follow_redirects=False to fetch and handle the redirect yourself.
  4. wxy8wxy commented on Sep 18, 2021

    @wxy8wxy
    Author

    AsyncHTTPClient also has the same error. The CurlAsyncHTTPClient works
    Thanks!

  5. kindernerd commented on Apr 25, 2025

    @kindernerd

    is there a solution without CurlAsyncHTTPClient? stuck in the same situation

  6. bdarnell commented on Apr 25, 2025

    @bdarnell
    Member

    The two known workarounds are the ones mentioned in my previous comment. If you can't use pycurl, you can pass follow_redirects=False and handle the redirects yourself, although this is a little more code on your side.

    You might also be able to use something like tornado.gen.with_timeout and get timeouts there instead of from the http client itself, although I haven't tried this and I'm not sure if it would clean up all resources correctly.

  7. kindernerd commented on Apr 25, 2025

    @kindernerd

    The two known workarounds are the ones mentioned in my previous comment. If you can't use pycurl, you can pass follow_redirects=False and handle the redirects yourself, although this is a little more code on your side.

    You might also be able to use something like tornado.gen.with_timeout and get timeouts there instead of from the http client itself, although I haven't tried this and I'm not sure if it would clean up all resources correctly.

    Thx for the very detailed explanation

  8. bdarnell commented on Nov 13, 2026

    @bdarnell
    Member

    This was fixed in Tornado 6.6.1 and in PR #3878 for the master branch.

  9. added 2 commits that reference this issue on Nov 13, 2026
    40348b6
    05bccb5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions