diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-12-01 11:07:45 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-12-01 11:07:45 (GMT) |
commit | b491e0521fd6e1a2e6f3e6354a2a296c7c8a2915 (patch) | |
tree | 0d0a19d7f5e62bd46298541a9ad9816abb25d631 /Lib/http | |
parent | 9cba9895028fcb24f242a3577d39f4d43198a0bc (diff) | |
download | cpython-b491e0521fd6e1a2e6f3e6354a2a296c7c8a2915.zip cpython-b491e0521fd6e1a2e6f3e6354a2a296c7c8a2915.tar.gz cpython-b491e0521fd6e1a2e6f3e6354a2a296c7c8a2915.tar.bz2 |
Issue #21032. Fixed socket leak if HTTPConnection.getresponse() fails.
Original patch by Martin Panter.
Diffstat (limited to 'Lib/http')
-rw-r--r-- | Lib/http/client.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py index cb1a535..281e7f2 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -1169,18 +1169,22 @@ class HTTPConnection: else: response = self.response_class(self.sock, method=self._method) - response.begin() - assert response.will_close != _UNKNOWN - self.__state = _CS_IDLE + try: + response.begin() + assert response.will_close != _UNKNOWN + self.__state = _CS_IDLE - if response.will_close: - # this effectively passes the connection to the response - self.close() - else: - # remember this, so we can tell when it is complete - self.__response = response + if response.will_close: + # this effectively passes the connection to the response + self.close() + else: + # remember this, so we can tell when it is complete + self.__response = response - return response + return response + except: + response.close() + raise try: import ssl |