Python Google Cloud Function Connection reset by peer

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..