firebase / firebase-admin-python

Firebase Admin Python SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
988 stars 300 forks source link

firestore times out when using default DNS resolver #783

Open sergiocampama opened 2 months ago

sergiocampama commented 2 months ago
import asyncio
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore_async
import sys

async def main():
  user_id = sys.argv[1]

  cred = credentials.Certificate("credentials.json")
  firebase_admin.initialize_app(cred)

  db = firestore_async.client()

  user_ref = db.collection("users").document(user_id)
  user = await user_ref.get()
  print(user)

if __name__ == "__main__":
  asyncio.run(main())

This code, using a firebase service account credential, and a database with a users table, will hang for 60 seconds and will fail with a DNS error, this one:

D0408 14:38:20.114377000 7971737600 grpc_ares_wrapper.cc:723]          (c-ares resolver) request:0x60000318e4e0 on_hostbyname_done_locked: C-ares status is not ARES_SUCCESS qtype=AAAA name=firestore.googleapis.com is_balancer=0: DNS query cancelled
D0408 14:38:20.114381000 7971737600 grpc_ares_wrapper.cc:723]          (c-ares resolver) request:0x60000318e4e0 on_hostbyname_done_locked: C-ares status is not ARES_SUCCESS qtype=A name=firestore.googleapis.com is_balancer=0: DNS query cancelled
...
D0408 14:38:20.114467000 7971737600 dns_resolver_ares.cc:328]          (c-ares resolver) resolver:0x600003f8d4a0 dns resolution failed: UNKNOWN:C-ares status is not ARES_SUCCESS qtype=A name=firestore.googleapis.com is_balancer=0: DNS query cancelled {created_time:"2024-04-08T14:38:20.114389-04:00", children:[UNKNOWN:C-ares status is not ARES_SUCCESS qtype=AAAA name=firestore.googleapis.com is_balancer=0: DNS query cancelled {created_time:"2024-04-08T14:38:20.114379-04:00"}]}

This is with firebase-admin 6.5.0 and python 3.12.2

Workaround

Call the python script with this environment variable:

GRPC_DNS_RESOLVER=native

works around the issue.

google-oss-bot commented 2 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.