diff --git a/granian/wsgi.py b/granian/wsgi.py index c14fd34d..3af5cab4 100644 --- a/granian/wsgi.py +++ b/granian/wsgi.py @@ -62,9 +62,13 @@ def start_response( resp.headers = headers rv = callback(environ, start_response) - body = b"".join(rv) - if hasattr(rv, "close"): - rv.close() + + try: + body = b"".join(rv) + finally: + if hasattr(rv, "close"): + rv.close() + return (resp.status, resp.headers, body) return wrapper