Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

query.onSnapshot: Error 4 (timeout/unavailable) when querying large collections #1040

Description

@merlinnot

Environment details

  • OS: Darwin Kernel Version 19.4.0
  • Node.js version: 12, 14
  • npm version: 6.14.4
  • @google-cloud/firestore version: 3.7.4

Steps to reproduce

Query a large collection using query.onSnapshot on a slow network connection or large enough collection. In my case I open four queries for four distinct collections of ~35k documents, each ~100kBs in size. After ~90 seconds, ~40k documents fetched, an error occurs:

Error: Error 4: The datastore operation timed out, or the data was temporarily unavailable.
    at QueryWatch.onData (/my-project-path/node_modules/@google-cloud/firestore/build/src/watch.js:346:34)
    at PassThrough.<anonymous> (/my-project-path/node_modules/@google-cloud/firestore/build/src/watch.js:284:26)
    at PassThrough.emit (events.js:311:20)
    at PassThrough.EventEmitter.emit (domain.js:482:12)
    at addChunk (_stream_readable.js:294:12)
    at readableAddChunk (_stream_readable.js:275:11)
    at PassThrough.Readable.push (_stream_readable.js:209:10)
    at PassThrough.Transform.push (_stream_transform.js:152:32)
    at PassThrough.afterTransform (_stream_transform.js:96:10)
    at PassThrough._transform (_stream_passthrough.js:46:3)

API response from QueryWatch.onData:

remove {
  targetIds: [ 1 ],
  targetChangeType: 'REMOVE',
  cause: {
    details: [],
    code: 4,
    message: 'The datastore operation timed out, or the data was temporarily unavailable.'
  },
  resumeToken: <Buffer >,
  readTime: null
}

Metadata

Metadata

Labels

api: firestoreIssues related to the googleapis/nodejs-firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

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