From: Graham Dumpleton Date: Mon, 17 Jun 2013 05:49:42 +0000 (+1000) Subject: WSGI specification requires that close() be called on iterable no matter what happens. X-Git-Tag: v3.2.0b1~120^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72556cf9d6058fa99478fd59bf9933a2326a35fc;p=thirdparty%2Ftornado.git WSGI specification requires that close() be called on iterable no matter what happens. --- diff --git a/tornado/wsgi.py b/tornado/wsgi.py index 6b5bfb8f6..5e25a5647 100644 --- a/tornado/wsgi.py +++ b/tornado/wsgi.py @@ -242,10 +242,12 @@ class WSGIContainer(object): return response.append app_response = self.wsgi_application( WSGIContainer.environ(request), start_response) - response.extend(app_response) - body = b"".join(response) - if hasattr(app_response, "close"): - app_response.close() + try: + response.extend(app_response) + body = b"".join(response) + finally: + if hasattr(app_response, "close"): + app_response.close() if not data: raise Exception("WSGI app did not call start_response")