Skip to content

Commit 1f5fcf7

Browse files
authored
Prevent requests from hanging on SSL handshake issue by adding a max t.o. (googleapis#8207)
* Prevent requests from hanging on SSL handshake issue by adding a max timeout of 5 minutes * rename and reuse constant * use named arg
1 parent c4195de commit 1f5fcf7

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

core/google/cloud/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"for help on authentication with this library."
3434
)
3535

36+
# Default timeout for auth requests.
37+
_CREDENTIALS_REFRESH_TIMEOUT = 300
38+
3639

3740
class _ClientFactoryMixin(object):
3841
"""Mixin to allow factories that create credentials.
@@ -153,7 +156,8 @@ def _http(self):
153156
"""
154157
if self._http_internal is None:
155158
self._http_internal = google.auth.transport.requests.AuthorizedSession(
156-
self._credentials
159+
self._credentials,
160+
refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT,
157161
)
158162
return self._http_internal
159163

core/tests/unit/test_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def test__http_property_existing(self):
122122
self.assertIs(client._http, http)
123123

124124
def test__http_property_new(self):
125+
from google.cloud.client import _CREDENTIALS_REFRESH_TIMEOUT
125126
credentials = _make_credentials()
126127
client = self._make_one(credentials=credentials)
127128
self.assertIsNone(client._http_internal)
@@ -133,7 +134,7 @@ def test__http_property_new(self):
133134
with authorized_session_patch as AuthorizedSession:
134135
self.assertIs(client._http, mock.sentinel.http)
135136
# Check the mock.
136-
AuthorizedSession.assert_called_once_with(credentials)
137+
AuthorizedSession.assert_called_once_with(credentials, refresh_timeout=_CREDENTIALS_REFRESH_TIMEOUT)
137138
# Make sure the cached value is used on subsequent access.
138139
self.assertIs(client._http_internal, mock.sentinel.http)
139140
self.assertIs(client._http, mock.sentinel.http)

0 commit comments

Comments
 (0)