As detailed here: https://issuetracker.google.com/issues/113672049
Cross-posted here: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/5879)
I'm getting a connection reset error when using the Firebase Storage API from a Google Cloud Function in Python.
The deployed function is calling one blob-get i.e.
from firebase_admin import storage
def fn(request):
bucket = 'my-firebase-bucket'
path = '/thing'
blob = storage.bucket(bucket).get_blob(path)
The failure is intermittent; the function has around a 90% success rate.
It seems more likely to fail the first time the function is called after it is deployed.
Cloud functions are stateless, but can re-use global state from previous invocations. This is explained in tips and these docs.
Using global state with retries should give you a more robust function:
from tenacity import retry, stop_after_attempt, wait_random
from firebase_admin import storage
@retry(stop=stop_after_attempt(3), wait=wait_random(min=1, max=2))
def get_bucket(storage):
return storage.bucket('my-firebase-bucket')
@retry(stop=stop_after_attempt(3), wait=wait_random(min=1, max=2))
def get_blob(bucket, path):
return bucket.get_blob(path)
bucket = get_bucket(storage)
def fn(request):
path = '/thing'
blob = get_blob(bucket, path)
# etc..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With