firebase-admin-python icon indicating copy to clipboard operation
firebase-admin-python copied to clipboard

firestore times out when using default DNS resolver

Open sergiocampama opened this issue 1 year ago • 2 comments

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.

sergiocampama avatar Apr 08 '24 18:04 sergiocampama

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

google-oss-bot avatar Apr 08 '24 18:04 google-oss-bot