diff --git a/Lib/http/client.py b/Lib/http/client.py index 4b9a61cfc1159f..15b5327332d202 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -1449,7 +1449,7 @@ def getresponse(self): return response except: - response.close() + self.close() raise try: diff --git a/Misc/NEWS.d/next/Library/2025-11-29-00-52-37.gh-issue-141938.ZADQRl.rst b/Misc/NEWS.d/next/Library/2025-11-29-00-52-37.gh-issue-141938.ZADQRl.rst new file mode 100644 index 00000000000000..755e322ccc5553 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-11-29-00-52-37.gh-issue-141938.ZADQRl.rst @@ -0,0 +1,4 @@ +Fix :class:`http.client.HTTPConnection` to properly reset its internal state when +reading the response raises an exception such as :exc:`TimeoutError`, ensuring +the connection can be reused or raises appropriate errors on subsequent +requests.