Skip to content

Large changesets over slow connections result in uncontrollable usage-metered long-polling loops #2683

Closed
@djsweet

Description

@djsweet

[REQUIRED] Describe your environment

  • Operating System version: Windows 10 Version 1909
  • Browser version: Version 80.0.3987.116 (Official Build) (64-bit)
  • Firebase SDK version: 7.9.1
  • Firebase Product: firestore

[REQUIRED] Describe the problem

We have encountered sporadic periods of quadrupled document read rates since early January 2020. We have narrowed the cause down to a pathological behavior of the Firebase SDK dealing with large changesets of 15,000 deleted documents and 15,000 added documents over slow Internet connections.

Clients with slow Internet connections will enter an uncontrollable, endless long-polling loop when these changes are encountered in snapshot listeners. The document additions seem to be reported to SDK consumers, but document removals are not. Each of these long-polling sessions counts the entire deleted document count against our read quotas, even though nothing is being passed to the SDK consumer.

Steps to reproduce:

I have prepared a sample project that simulates the exact conditions necessary to trigger this bug. A "server" script deletes and then creates 15,000 documents against a Firestore database, and a client attempts to react to these changes. The client's network connection is throttled using the Slow 3G preset in the Google Chrome Developer Console.

We see an initial HTTP connection that takes 270s to complete, transmitting 13.2 MB of data, which results in the client reporting all of the document additions but none of the document removals.

Read Spike First Contact

After this, we enter a state where follow-up HTTP connections taking 70 seconds each are constantly retried. Each connection transmits 3.3 MB of data, but the consumer of the SDK is not passed any information regarding changes.

Project State 45 minutes later

After running this client for an hour with no actual database changes, we see that we will be charged for 800,000 document reads.

Project State Full Hour Later

Because nothing has actually changed in the database during this period, and we are not actually able to observe changes from the client, we expect to not be charged for any reads.

Relevant Code:

See https://github.com/djsweet/firestore-read-spike-bug-report for an environment which reproduces this problem.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions