I'm using the python google-cloud-storage library. I have code as follows:
with open("config/google_auth.json") as f:
credential_info = json.load(f)
credentials = service_account.Credentials.from_service_account_info(credential_info)
client = storage.Client(project=credential_info["project_id"], credentials=credentials)
bucket = client.get_bucket(BUCKET_NAME)
When I run this code locally, get_bucket takes a long time to resolve. It took 105 seconds, before finishing, but did complete successfully.
Weirder yet, adding a timeout argument changes the behavior. The following call to get bucket runs in 5 seconds, completing successfully:
bucket = client.get_bucket(BUCKET_NAME, timeout=1)
Setting timeout=5 causes it to take 25 seconds.
Setting timeout=0.1 causes it to take less than a second.
I'm on the latest version of the library (1.33.0 as of time of posting) with Python 3.6.2
Why is get_bucket so slow? Why does passing a timeout argument make it run faster? And why, when I pass the timeout argument, does the call return successfully despite taking substantially longer than the timeout?