From b42c61c88ebabbd20ba3bb6d797ff73249ab2b07 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Fri, 9 Jul 2010 18:15:12 -0700 Subject: [PATCH] In AsyncHTTPClient2, disable IPv6 for versions of libcurl with the socket-reopening bug (i.e. <= 7.21.0). (this can be overridden if needed with a prepare_curl_callback) --- tornado/httpclient.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 842950db0..26adf8527 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -329,10 +329,10 @@ class AsyncHTTPClient2(object): the kqueue-based IOLoop (mac/bsd), but it may also occur on epoll (linux) and, in principle, for non-localhost sites. While the bug is unrelated to IPv6, disabling IPv6 will avoid the - most common manifestations of the bug (use a prepare_curl_callback that - calls curl.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_V4)). - The underlying cause is a libcurl bug that has been confirmed to be - present in versions 7.20.0 and 7.21.0: + most common manifestations of the bug, so this class disables IPv6 when + it detects an affected version of libcurl. + The underlying cause is a libcurl bug in versions up to and including + 7.21.0 (it will be fixed in the not-yet-released 7.21.1) http://sourceforge.net/tracker/?func=detail&aid=3017819&group_id=976&atid=100976 """ _ASYNC_CLIENTS = weakref.WeakKeyDictionary() @@ -469,6 +469,11 @@ class AsyncHTTPClient2(object): "callback": callback, "start_time": time.time(), } + # Disable IPv6 to mitigate the effects of this bug + # on curl versions <= 7.21.0 + # http://sourceforge.net/tracker/?func=detail&aid=3017819&group_id=976&atid=100976 + if pycurl.version_info()[2] <= 0x71500: # 7.21.0 + curl.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_V4) _curl_setup_request(curl, request, curl.info["buffer"], curl.info["headers"]) self._multi.add_handle(curl) -- 2.47.3