From 72556cf9d6058fa99478fd59bf9933a2326a35fc Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Mon, 17 Jun 2013 15:49:42 +1000 Subject: [PATCH] WSGI specification requires that close() be called on iterable no matter what happens. --- tornado/wsgi.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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") -- 2.47.2