Skip to content

Commit a7bd694

Browse files
fix: run credential refresh of connectors in threads (#512)
1 parent 5fe0823 commit a7bd694

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

google/cloud/alloydbconnector/async_connector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ async def connect(
216216
logger.debug(f"['{instance_uri}']: Connecting to {ip_address}:5433")
217217

218218
# callable to be used for auto IAM authn
219-
def get_authentication_token() -> str:
219+
async def get_authentication_token() -> str:
220220
"""Get OAuth2 access token to be used for IAM database authentication"""
221221
# refresh credentials if expired
222222
if not self._db_credentials.valid:
223223
request = google.auth.transport.requests.Request()
224-
self._db_credentials.refresh(request)
224+
await asyncio.to_thread(self._db_credentials.refresh, request)
225225
return self._db_credentials.token
226226

227227
# if enable_iam_auth is set, use auth token as database password

tests/unit/test_async_connector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ async def test_connect_iam_authn(credentials: FakeCredentials) -> None:
240240

241241
async def custom_connect(*_: Any, **kwargs: Any) -> bool:
242242
passwd = kwargs.pop("password")
243-
passwd()
243+
await passwd()
244244

245245
# patch db connection creation
246246
with patch(
@@ -272,7 +272,7 @@ async def test_connect_db_credentials_iam_authn(credentials: FakeCredentials) ->
272272

273273
async def custom_connect(*_: Any, **kwargs: Any) -> bool:
274274
passwd = kwargs.pop("password")
275-
passwd()
275+
await passwd()
276276

277277
# patch db connection creation
278278
with patch(

0 commit comments

Comments
 (0)