summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-10-21 15:37:43 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-10-21 15:37:43 (GMT)
commitbd26b5463eb4547a2c679e562180364b0767cf32 (patch)
treeb1fa315fc81dc57e52d772912cbbfcee721dc112
parentca4a52513bf7d08d4ba26b18d9cba4afd5c02176 (diff)
downloadcpython-bd26b5463eb4547a2c679e562180364b0767cf32.zip
cpython-bd26b5463eb4547a2c679e562180364b0767cf32.tar.gz
cpython-bd26b5463eb4547a2c679e562180364b0767cf32.tar.bz2
Issue #12692: Fix resource leak in urllib.request.
-rw-r--r--Lib/test/test_urllib2.py1
-rw-r--r--Lib/urllib/request.py6
-rw-r--r--Misc/NEWS3
3 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 7ae1553..00ee669 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -302,6 +302,7 @@ class MockHTTPClass:
self.req_headers = []
self.data = None
self.raise_on_endheaders = False
+ self.sock = None
self._tunnel_headers = {}
def __call__(self, host, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 88f3ce1..250d89e 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1255,6 +1255,12 @@ class AbstractHTTPHandler(BaseHandler):
raise URLError(err)
else:
r = h.getresponse()
+ # If the server does not send us a 'Connection: close' header,
+ # HTTPConnection assumes the socket should be left open. Manually
+ # mark the socket to be closed when this response object goes away.
+ if h.sock:
+ h.sock.close()
+ h.sock = None
r.url = req.get_full_url()
# This line replaces the .msg attribute of the HTTPResponse
diff --git a/Misc/NEWS b/Misc/NEWS
index 4af7d0a..fae3f13 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -59,6 +59,9 @@ Core and Builtins
Library
-------
+- Issue #12692: Fix resource leak in urllib.request when talking to an HTTP
+ server that does not include a "Connection: close" header in its responses.
+
- Issue #12034: Fix bogus caching of result in check_GetFinalPathNameByHandle.
Patch by Atsuo Ishimoto.