mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue #21032. Fixed socket leak if HTTPConnection.getresponse() fails.
Original patch by Martin Panter.
This commit is contained in:
parent
9cba989502
commit
b491e0521f
3 changed files with 41 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue