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

Retrieving document snapshots concurrently from different threads leads to a deadlock #913

Open
sergeyle opened this issue Apr 12, 2024 · 0 comments
Assignees
Labels
api: firestore Issues related to the googleapis/python-firestore API.

Comments

@sergeyle
Copy link

Calling get() to retrieve a document snapshot concurrently from different threads reliably leads to a deadlock. This was attempted on an M1 Mac and a GCE Cloud Console Linux.

This was tried on google-cloud-firestore=(2.15.0|2.16.0)

Code to reproduce the bug:

import threading
import firebase_admin
from firebase_admin import credentials, firestore


__app = firebase_admin.initialize_app(credentials.ApplicationDefault())

def query_firestore(docid):
    db = firestore.client(__app)
    coll = db.collection("mycollection")
    try:
        print("About to query firestore")
        doc = coll.document(docid).get().to_dict()
        # The flow never reaches here.
        print(f"Document data: {doc}")
    except Exception as e:
        print(f"Error querying Firestore: {e}")


def start_threads(n, docid):
    threads = []
    for _ in range(n):
        thread = threading.Thread(target=query_firestore, args=(docid,))
        threads.append(thread)
        thread.start()
    # Wait for all threads to complete
    for thread in threads:
        thread.join()

if __name__ == "__main__":
    N = 5  # Number of threads
    docid = "1234"
    start_threads(N, docid)
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/python-firestore API. label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API.
Projects
None yet
Development

No branches or pull requests

2 participants