Skip to content

Prevent requests from hanging on SSL handshake issue by adding a max t.o. #8207

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

Merged
merged 3 commits into from
Jun 5, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/google/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"for help on authentication with this library."
)

# Default timeout for auth requests.
_CREDENTIALS_REFRESH_TIMEOUT = 300


class _ClientFactoryMixin(object):
"""Mixin to allow factories that create credentials.
Expand Down Expand Up @@ -153,7 +156,8 @@ def _http(self):
"""
if self._http_internal is None:
self._http_internal = google.auth.transport.requests.AuthorizedSession(
self._credentials
self._credentials,
refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT,
)
return self._http_internal

Expand Down
3 changes: 2 additions & 1 deletion core/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def test__http_property_existing(self):
self.assertIs(client._http, http)

def test__http_property_new(self):
from google.cloud.client import _CREDENTIALS_REFRESH_TIMEOUT
credentials = _make_credentials()
client = self._make_one(credentials=credentials)
self.assertIsNone(client._http_internal)
Expand All @@ -133,7 +134,7 @@ def test__http_property_new(self):
with authorized_session_patch as AuthorizedSession:
self.assertIs(client._http, mock.sentinel.http)
# Check the mock.
AuthorizedSession.assert_called_once_with(credentials)
AuthorizedSession.assert_called_once_with(credentials, refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT)
# Make sure the cached value is used on subsequent access.
self.assertIs(client._http_internal, mock.sentinel.http)
self.assertIs(client._http, mock.sentinel.http)
Expand Down