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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Catch ECONNRESET and other errors more reliably #1147

Merged
merged 1 commit into from Jan 13, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions googleapiclient/http.py
Expand Up @@ -28,17 +28,14 @@
from six import BytesIO, StringIO
from six.moves.urllib.parse import urlparse, urlunparse, quote, unquote

import base64
import copy
import gzip
import httplib2
import json
import logging
import mimetypes
import os
import random
import socket
import sys
import time
import uuid

Expand Down Expand Up @@ -190,11 +187,16 @@ def _retry_request(
exception = connection_error
except socket.error as socket_error:
# errno's contents differ by platform, so we have to match by name.
# Some of these same errors may have been caught above, e.g. ECONNRESET *should* be
# raised as a ConnectionError, but some libraries will raise it as a socket.error
# with an errno corresponding to ECONNRESET
if socket.errno.errorcode.get(socket_error.errno) not in {
"WSAETIMEDOUT",
"ETIMEDOUT",
"EPIPE",
"ECONNABORTED",
"ECONNREFUSED",
parthea marked this conversation as resolved.
Show resolved Hide resolved
"ECONNRESET",
}:
raise
exception = socket_error
Expand Down
4 changes: 2 additions & 2 deletions tests/test_http.py
Expand Up @@ -174,10 +174,10 @@ def request(self, *args, **kwargs):
# set errno to a non-retriable value
try:
# For Windows:
ex.errno = socket.errno.WSAECONNREFUSED
ex.errno = socket.errno.WSAEHOSTUNREACH
parthea marked this conversation as resolved.
Show resolved Hide resolved
except AttributeError:
# For Linux/Mac:
ex.errno = socket.errno.ECONNREFUSED
ex.errno = socket.errno.EHOSTUNREACH
# Now raise the correct timeout error.
raise ex

Expand Down