wsgicgi: call close() on iterable to avoid resource leaks stable
authorKonstantin Zemlyak <zart@zartsoft.ru>
Mon, 22 Mar 2010 15:16:27 +0100
branchstable
changeset 10753 a1cb8ca051c0
parent 10748 fb06e357e698
child 10754 0d454e1fa14a
child 10755 32023a0a389b
child 10778 e703af672d9d
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."
mercurial/hgweb/wsgicgi.py
--- a/mercurial/hgweb/wsgicgi.py	Sat Mar 20 14:47:05 2010 +0100
+++ b/mercurial/hgweb/wsgicgi.py	Mon Mar 22 15:16:27 2010 +0100
@@ -69,5 +69,9 @@
         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()