From 11f90d071801c9459671c218c318400b4de4fa13 Mon Sep 17 00:00:00 2001 From: Rhett Garber Date: Fri, 7 Dec 2012 16:13:57 -0800 Subject: [PATCH] Don't catch and hide exceptions caused by callbacks in http client --- tornado/simple_httpclient.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index faff83c8..a5be937c 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -316,12 +316,20 @@ class _HTTPConnection(object): try: yield except Exception, e: - gen_log.warning("uncaught exception", exc_info=True) - self._run_callback(HTTPResponse(self.request, 599, error=e, - request_time=self.io_loop.time() - self.start_time, - )) - if hasattr(self, "stream"): - self.stream.close() + if self.final_callback: + gen_log.warning("uncaught exception", exc_info=True) + self._run_callback(HTTPResponse(self.request, 599, error=e, + request_time=self.io_loop.time() - self.start_time, + )) + + if hasattr(self, "stream"): + self.stream.close() + else: + # If our callback has already been called, we are probably + # catching an exception that is not caused by us but rather + # some child of our callback. Rather than drop it on the floor, + # pass it along. + raise def _on_close(self): if self.final_callback is not None: