google-cloud-go icon indicating copy to clipboard operation
google-cloud-go copied to clipboard

firestore: service is Unavailable on every Next() call yet iterator never terminates

Open nikolaydubina opened this issue 4 months ago • 3 comments

Client

Firestore

Environment

go version go1.24.6 darwin/arm64

Code and Dependencies

iter := ... .Documents(ctx)

doc, err := iter.Next()
// error here is "service unavailable". repeatedly for every call.

// but further .Next() calls never return `iterator.Done`
// this can cause **infinite** calls to this service

please fix

nikolaydubina avatar Aug 12 '25 10:08 nikolaydubina

When you call Documents(ctx) on a Query or CollectionRef, you get a DocumentIterator that is backed by a queryDocumentIterator. The next() method of queryDocumentIterator streams results from the RunQuery RPC. If a Recv() call on this stream fails with a non-EOF error (like "service unavailable"), the error is returned and the iterator is permanently "poisoned" with that error. Subsequent calls to Next() will just return the cached error, and there are no infinite calls to the service. While this means the iterator never returns iterator.Done, it also doesn't cause an infinite retry loop in the client library itself.

bhshkh avatar Sep 17 '25 08:09 bhshkh

thank god, we don't infinitely call backend at least!

nikolaydubina avatar Oct 12 '25 05:10 nikolaydubina

Subsequent calls to Next() will just return the cached error, and there are no infinite calls to the service.

not true! we just observed that it does not! it infinitely calls iterator!

nikolaydubina avatar Nov 14 '25 10:11 nikolaydubina