Skip to content

Firestore listenForChanges creates duplicate listeners causing app crash #2253

Description

@TheNoumanDev

Problem:
When using listenForChanges: true on Firestore APIs, the app progressively slows down and eventually crashes after multiple updates from Firestore.

Symptoms:

  • App becomes noticeably slower after 8-9 Firestore updates
  • App crashes after 12-15 updates
  • Performance degradation is exponential, not linear

Root Cause:
FirestoreAPIProvider stores subscriptions in a List without deduplication. When the same API is called multiple times (via tab switches, navigation callbacks, screen refreshes), new listeners are created each time instead of reusing existing ones.
Each Firestore update then fires ALL accumulated listeners, causing exponential callback execution.

Secondary Issue:

When the page disposes while Firestore listeners are still active, the listener tries to fire on a closed EventBus, causing:
Bad state: Cannot add new events after calling close

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions