Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datastore emulator causes firebase admin to hang #790

Open
pb-jeff-oneill opened this issue Jun 5, 2024 · 2 comments
Open

Datastore emulator causes firebase admin to hang #790

pb-jeff-oneill opened this issue Jun 5, 2024 · 2 comments

Comments

@pb-jeff-oneill
Copy link

pb-jeff-oneill commented Jun 5, 2024

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Mac 14.5
  • Firebase Product: firebase-admin==6.2.0 and firebase-admin==6.5.0
  • Python version: 3.11.4
  • Pip version: 24.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

This problem started around June 1. Before, I have been doing this for several years without any issues.

The problem is that auth.get_user_by_email() freezes and it is caused by some interaction with running the cloud datastore emulator locally. This happens with either the older emulator (gcloud beta emulators datastore start) or the newer one (gcloud emulators firestore start ). I have tried downgrading gcloud and two versions of firebase-admin listed above.

Run the script below. At auth.get_user_by_email(), the script hangs indefinitely with no output. You can't even ctrl-c to stop the script. You need to kill -9 in a separate terminal window.

If you comment out the three lines starting with with datastore_client.context():, then auth.get_user_by_email() works.

Since the code just freezes, I am at a loss as to how to debug.

Relevant Code:

import os
from google.cloud import ndb
import firebase_admin
from firebase_admin import auth, initialize_app

print('starting')

class User(ndb.Model):
    email = ndb.StringProperty(required=True)

os.environ['DATASTORE_DATASET'] = 'my-project'
os.environ['DATASTORE_EMULATOR_HOST'] = 'localhost:8081'
os.environ['DATASTORE_EMULATOR_HOST_PATH'] = 'localhost:8081/datastore'
os.environ['DATASTORE_HOST'] = 'http://localhost:8081'
os.environ['DATASTORE_PROJECT_ID']= 'my-project'

datastore_client = ndb.Client('my-project')

if not firebase_admin._apps:
    initialize_app()

email = 'me@example.com'

with datastore_client.context():
    user = User.get_by_id(email)
    print(user)

# This hangs and you can't even ctrl-c to stop.
# Works if datastore client stuff is commented out.
fb_user = auth.get_user_by_email(email)
print(fb_user)
@google-oss-bot
Copy link

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

@pb-jeff-oneill
Copy link
Author

It seems to be IPv4/IPv6 related because changing from localhost to 127.0.0.1 fixes it.

What ever the cause, it seems that it shouldn't cause auth.get_user_by_email() to hang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants