diff --git a/tornado/wsgi.py b/tornado/wsgi.py index 6b5bfb8f6a..5e25a5647a 100644 --- a/tornado/wsgi.py +++ b/tornado/wsgi.py @@ -242,10 +242,12 @@ def start_response(status, response_headers, exc_info=None): 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")