alloydb-python-connector icon indicating copy to clipboard operation
alloydb-python-connector copied to clipboard

Token refresh uses blocking I/O in async function

Open anuraaga opened this issue 1 year ago • 2 comments

Bug Description

Token refresh in the async Client class uses the requests.Request transport of the google auth library

https://github.com/GoogleCloudPlatform/alloydb-python-connector/blob/6cc4c8e7bff360ce35525ae84d409ce1ebc284bf/google/cloud/alloydb/connector/client.py#L186-L188

This means it is doing blocking I/O on the asyncio loop. At the minimum, the fetch seems like it needs to be delegated to a thread with asyncio.to_thread.

For reference, google-auth-library-python does have some baking experimental APIs for async

https://github.com/googleapis/google-auth-library-python/blob/main/google/auth/transport/_aiohttp_requests.py https://github.com/googleapis/google-auth-library-python/blob/main/google/auth/_default_async.py

However, assuming using the experimental APIs was ok, it's probably still not ready for general use because at least, impersonated credentials don't yet have an async version (in certain token refresh logic I've written, I use the async APIs for normal creds and to_thread for impersonated, but it seems too complicated for this library).

https://github.com/googleapis/google-auth-library-python/blob/main/google/auth/impersonated_credentials.py

Example code (or command)

No response

Stacktrace

No response

Steps to reproduce?

  1. ?
  2. ?
  3. ? ...

Environment

  1. OS type and version:
  2. Python version:
  3. AlloyDB Python Connector version:

Additional Details

No response

anuraaga avatar Feb 07 '24 03:02 anuraaga