Commit 838ba4ac authored by Nadeem Vawda's avatar Nadeem Vawda

Issue #12692: Fix resource leak in urllib.request.

parent 348a4887
...@@ -302,6 +302,7 @@ class MockHTTPClass: ...@@ -302,6 +302,7 @@ class MockHTTPClass:
self.req_headers = [] self.req_headers = []
self.data = None self.data = None
self.raise_on_endheaders = False self.raise_on_endheaders = False
self.sock = None
self._tunnel_headers = {} self._tunnel_headers = {}
def __call__(self, host, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): def __call__(self, host, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
......
...@@ -1255,6 +1255,12 @@ class AbstractHTTPHandler(BaseHandler): ...@@ -1255,6 +1255,12 @@ class AbstractHTTPHandler(BaseHandler):
raise URLError(err) raise URLError(err)
else: else:
r = h.getresponse() 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() r.url = req.get_full_url()
# This line replaces the .msg attribute of the HTTPResponse # This line replaces the .msg attribute of the HTTPResponse
......
...@@ -59,6 +59,9 @@ Core and Builtins ...@@ -59,6 +59,9 @@ Core and Builtins
Library 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. - Issue #12034: Fix bogus caching of result in check_GetFinalPathNameByHandle.
Patch by Atsuo Ishimoto. Patch by Atsuo Ishimoto.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment