From cf766125d50e2073196f218710b39d0e27aacf31 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 18 Apr 2015 18:15:14 -0400 Subject: [PATCH] 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. --- tornado/curl_httpclient.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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 -- 2.47.3