From: Ben Darnell Date: Sat, 18 Apr 2015 22:15:14 +0000 (-0400) Subject: Fix exception handling in CurlAsyncHTTPClient._process_queue. X-Git-Tag: v4.2.0b1~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cf766125d50e2073196f218710b39d0e27aacf31;p=thirdparty%2Ftornado.git Fix exception handling in CurlAsyncHTTPClient._process_queue. Previously it would allow exceptions to escape, which worked only if _process_queue were called by fetch_impl instead of _finish_pending_requests. Closes #1413. --- diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index 87312de23..ae6f114a9 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -208,9 +208,25 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): "callback": callback, "curl_start_time": time.time(), } - self._curl_setup_request(curl, request, curl.info["buffer"], - curl.info["headers"]) - self._multi.add_handle(curl) + try: + self._curl_setup_request( + curl, request, curl.info["buffer"], + curl.info["headers"]) + except Exception as e: + # If there was an error in setup, pass it on + # to the callback. Note that allowing the + # error to escape here will appear to work + # most of the time since we are still in the + # caller's original stack frame, but when + # _process_queue() is called from + # _finish_pending_requests the exceptions have + # nowhere to go. + callback(HTTPResponse( + request=request, + code=599, + error=e)) + else: + self._multi.add_handle(curl) if not started: break