Skip to content

Commit 6fa950c

Browse files
committed
Fix a case where callbacks could be called more than once in error conditions.
1 parent 3951d59 commit 6fa950c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tornado/simple_httpclient.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,16 @@ def cleanup(self):
240240
except Exception, e:
241241
logging.warning("uncaught exception", exc_info=True)
242242
if self.callback is not None:
243-
self.callback(HTTPResponse(self.request, 599, error=e))
243+
callback = self.callback
244244
self.callback = None
245+
callback(HTTPResponse(self.request, 599, error=e))
245246

246247
def _on_close(self):
247248
if self.callback is not None:
248-
self.callback(HTTPResponse(self.request, 599,
249-
error=HTTPError(599,
250-
"Connection closed")))
249+
callback = self.callback
251250
self.callback = None
251+
callback(HTTPResponse(self.request, 599,
252+
error=HTTPError(599, "Connection closed")))
252253

253254
def _on_headers(self, data):
254255
first_line, _, header_data = data.partition("\r\n")

0 commit comments

Comments
 (0)