GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Firestore Realtime Listener Timing Out · Issue #2888 · googleapis/google-cloud-java

Firestore Realtime Listener Timing Out #2888

New issue
Copy link
New issue
Copy link
Closed
Closed
Firestore Realtime Listener Timing Out#2888
Copy link
Assignees
schmidt-sebastian
Labels
api: firestoreIssues related to the Firestore API.type: questionRequest for information or clarification. Not an issue.

Description

@ad1269
ad1269
opened on Feb 10, 2018
Issue body actions

I'm trying to use Firestore in order to set up realtime listeners for a collection. Whenever a document is added, modified, or deleted in a collection, I want the listener to be called. My code is currently working for one collection, but when I try the same code on a larger collection, it fails with the error:

Listen failed: com.google.cloud.firestore.FirestoreException: Backend ended Listen stream: The datastore operation timed out, or the data was temporarily unavailable.

How should I deal with this issue in order to track changes in this collection? Can I manually set a higher time out threshold or use some other technique? My code implementation is below for reference:

/**
 * Sets up a listener at the given collection reference. When changes are made in this collection, it writes a flat
 * text file for import into backend.
 * @param collectionReference The Collection Reference that we want to listen to for changes.
 */
public static void listenToCollection(CollectionReference collectionReference) {

    AtomicBoolean initialUpdate = new AtomicBoolean(true);

    System.out.println("Initializing listener for: " + collectionReference.getId());

    collectionReference.addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirestoreException e) {
            // Error Handling
            if (e != null) {
                System.err.println("Listen failed: " + e);
                return;
            }

            // If this is the first time this function is called, it's simply reading everything in the collection
            // We don't care about the initial value, only the updates, so we simply ignore the first call
            if (initialUpdate.get()) {
                initialUpdate.set(false);
                System.out.println("Initial update complete...\nListener active for " + collectionReference.getId() + "...");
                return;
            }

            // A document has changed, propagate this back to backend by writing text file.
            for (DocumentChange dc : queryDocumentSnapshots.getDocumentChanges()) {

                String docId = dc.getDocument().getId();
                Map<String, Object> docData = dc.getDocument().getData();

                String folderPath = createFolderPath(collectionReference, docId, docData);

                switch (dc.getType()) {
                    case ADDED:
                        System.out.println("Document Created: " + docId);
                        writeMapToFile(docData, folderPath, "CREATE");
                        break;
                    case MODIFIED:
                        System.out.println("Document Updated: " + docId);
                        writeMapToFile(docData, folderPath, "UPDATE");
                        break;
                    case REMOVED:
                        System.out.println("Document Deleted: " + docId);
                        writeMapToFile(docData, folderPath, "DELETE");
                        break;
                    default:
                        break;
                }
            }

        }
    });
}

Activity

  1. pongad
    assigned
    schmidt-sebastian
    on Feb 12, 2018
  2. pongad
    added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    api: firestoreIssues related to the Firestore API.
    type: questionRequest for information or clarification. Not an issue.
    and removed
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Feb 12, 2018
  3. schmidt-sebastian commented on Feb 12, 2018

    @schmidt-sebastian
    schmidt-sebastian
    on Feb 12, 2018
    Contributor
    More actions

    @ad1269 Thanks for sending this over. This sounds like something that our backend team should take a look out. You shouldn't need to do anything special to work with larger collections.

    Can you let us know what collection sizes you are working with?

  4. ad1269 commented on Feb 12, 2018

    @ad1269
    ad1269
    on Feb 12, 2018
    Author
    More actions

    My collection is quite large. It consists of about 100,000 documents, with each document containing about 40 fields.

    I've found a work around for my problem by introducing a "Last_Updated" timestamp field, and only querying documents that have been updated within the last few days. Whenever my app changes a document, I also update the Last_Updated field.

    I'm happy to provide more information if that'll help the backend team, but I managed to fix my issue!

  5. sduskis commented on Dec 6, 2018

    @sduskis
    sduskis
    on Dec 6, 2018
    Contributor
    More actions

    The specific issue you have is resolved. There are a lot of ways you can communicate with the firebase team directly: https://firebase.google.com/support/. You can submit additional feature requests or have a discussion about how best to use FireStore with one of those methods.

    I'm closing this for now, until there's a new Firestore feature.

  6. sduskis
    closed this as completedon Dec 6, 2018
  7. chingor13
    added a commit that references this issue on Feb 20, 2026

    chore: Update generation configuration at Fri Feb 28 02:26:17 UTC 2025 (

    597b282
  8. suztomo
    added a commit that references this issue on Mar 9, 2026

    feat: Add support for FileSetSpec (#2888)

    3895bd9
  9. lqiu96
    added a commit that references this issue on Mar 20, 2026

    chore: Update generation configuration at Fri Feb 28 02:26:17 UTC 2025 (

    c591e8a
  10. chingor13
    added 5 commits that reference this issue on Mar 24, 2026

    feat: push SNAPSHOT versions of the hermetic build docker image (#2888)

    8bc060b

    chore(main): release 2.42.0 (#2847)

    c85602b

    deps: update dependency com.google.cloud:sdk-platform-java-config to …

    1c61385

    chore(main): release 6.59.0 (#2887)

    65df437

    chore: Update generation configuration at Tue Jan 21 02:20:38 UTC 2025 (

    525cd39
  11. rahul2393
    added a commit that references this issue on May 21, 2026

    fix: update local vRPC status to match the last session failure when …

    08235af
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @schmidt-sebastian
    schmidt-sebastian

Labels

api: firestoreIssues related to the Firestore API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.