# HG changeset patch # User Konstantin Zemlyak # Date 2010-03-22 14:16:27 # Node ID a1cb8ca051c01612ea0e6161b4d4419f6954e251 # Parent fb06e357e6982d878b1cc083a0a22d080527eb41 wsgicgi: call close() on iterable to avoid resource leaks Quoting PEP 333 (WSGI): "If the iterable returned by the application has a close() method, the server or gateway must call that method upon completion of the current request, whether the request was completed normally, or terminated early due to an error. (This is to support resource release by the application. This protocol is intended to complement PEP 325's generator support, and other common iterables with close() methods." diff --git a/mercurial/hgweb/wsgicgi.py b/mercurial/hgweb/wsgicgi.py --- a/mercurial/hgweb/wsgicgi.py +++ b/mercurial/hgweb/wsgicgi.py @@ -69,5 +69,9 @@ def launch(application): return write content = application(environ, start_response) - for chunk in content: - write(chunk) + try: + for chunk in content: + write(chunk) + finally: + if hasattr(content, 'close'): + content.close()