Skip to content

Commit a741ac1

Browse files
authored
Refine OSError handling in HTTP client
Handle specific OSError cases to prevent unnecessary connection closure.
1 parent afd2098 commit a741ac1

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Lib/http/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,11 +1344,12 @@ def request(self, method, url, body=None, headers={}, *,
13441344
"""Send a complete request to the server."""
13451345
try:
13461346
self._send_request(method, url, body, headers, encode_chunked)
1347-
except OSError:
1347+
except OSError as e:
13481348
# If the transmission fails (e.g. timeout), close the connection
13491349
# to reset the state machine to _CS_IDLE
1350+
if getattr(e, "errno", None) != errno.EPIPE:
13501351
self.close()
1351-
raise
1352+
raise
13521353

13531354
def _send_request(self, method, url, body, headers, encode_chunked):
13541355
# Honor explicitly requested Host: and Accept-Encoding: headers.

0 commit comments

Comments
 (0)