]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix exception handling in CurlAsyncHTTPClient._process_queue.
authorBen Darnell <ben@bendarnell.com>
Sat, 18 Apr 2015 22:15:14 +0000 (18:15 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 18 Apr 2015 22:15:14 +0000 (18:15 -0400)
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

index 87312de236c4823d9cb785bd3ff5c847442f76af..ae6f114a95b92912c30297e48936c43119c673f2 100644 (file)
@@ -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