Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading the actual request may trigger CONNRESET on a cached connection #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 20 additions & 23 deletions python3/httplib2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,16 +1004,18 @@ def _conn_request(self, conn, request_uri, method, body, headers):
errno_ = (e.args[0].errno if isinstance(e.args[0], socket.error) else e.errno)
if errno_ in (errno.ENETUNREACH, errno.EADDRNOTAVAIL) and i < RETRIES:
continue # retry on potentially transient errors
if errno_ in (errno.ECONNRESET, errno.EPIPE) and i == 1:
conn.close()
conn.connect()
continue # retry on closed connection
raise
except http.client.HTTPException:
if conn.sock is None:
conn.close()
if i < RETRIES-1:
conn.close()
conn.connect()
continue
else:
conn.close()
raise
raise
if i < RETRIES-1:
conn.close()
conn.connect()
Expand All @@ -1023,39 +1025,34 @@ def _conn_request(self, conn, request_uri, method, body, headers):
pass
try:
response = conn.getresponse()
content = b""
if method == "HEAD":
conn.close()
else:
content = response.read()
response = Response(response)
if method != "HEAD":
content = _decompressContent(response, content)
except (http.client.BadStatusLine, http.client.ResponseNotReady):
# If we get a BadStatusLine on the first try then that means
# the connection just went stale, so retry regardless of the
# number of RETRIES set.
conn.close()
if not seen_bad_status_line and i == 1:
i = 0
seen_bad_status_line = True
conn.close()
conn.connect()
continue
else:
conn.close()
raise
raise
except socket.timeout:
raise
except (socket.error, http.client.HTTPException):
except (socket.error, http.client.HTTPException) as e:
conn.close()
if i == 0:
conn.close()
errno_ = (e.args[0].errno if isinstance(e.args[0], socket.error) else e.errno)
if errno_ in (errno.ECONNRESET, errno.EPIPE) and i == 1:
conn.connect()
continue
else:
raise
else:
content = b""
if method == "HEAD":
conn.close()
else:
content = response.read()
response = Response(response)
if method != "HEAD":
content = _decompressContent(response, content)

raise
break
return (response, content)

Expand Down