From 71abb9fd0206ed704f00adb313b0db602655fa85 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Wed, 27 Jul 2011 21:04:22 -0700 Subject: [PATCH] More defensiveness about patterns that could lead to double callbacks. --- tornado/simple_httpclient.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index c684e745..c0d76aa6 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -204,10 +204,8 @@ class _HTTPConnection(object): def _on_timeout(self): self._timeout = None - if self.callback is not None: - self.callback(HTTPResponse(self.request, 599, - error=HTTPError(599, "Timeout"))) - self.callback = None + self._run_callback(HTTPResponse(self.request, 599, + error=HTTPError(599, "Timeout"))) self.stream.close() def _on_connect(self, parsed): @@ -348,8 +346,9 @@ class _HTTPConnection(object): new_request.max_redirects -= 1 del new_request.headers["Host"] new_request.original_request = original_request - self.client.fetch(new_request, self.callback) + callback = self.callback self.callback = None + self.client.fetch(new_request, callback) return response = HTTPResponse(original_request, self.code, headers=self.headers,