Sorry for the late followup, finally got around to looking at this again.
After investigating it further, I actually think there's a bug in the Firestore server implementation. From adding logging, I've observed that the same document is handled repeatedly and beyond a certain point, no new documents are received. (Note that the onSnapshot listener is never actually called either)
My code looks like this: (also uploaded this to
https://gist.github.com/mmmulani/29dbbeb3f165b4ff992ad18492e694fe for easier reading)
```
const docsSeen = new Set<string>();
let savedBlob = undefined;
admin.firestore.setLogFunction((msg) => {
const responseMarker = '[Firestore.requestStream]: Received response:';
if (msg.includes('JIHdYtkYCRgs0SzCOyRe8HDID33') && msg.includes(responseMarker)) {
const jsonText = msg.substring(msg.indexOf(responseMarker) + responseMarker.length + 1);
const responseValue = JSON.parse(jsonText);
console.log('Seen docs up to this point', docsSeen.size);
if (savedBlob) {
console.log('values match', equal(savedBlob, responseValue));
}
savedBlob = responseValue;
}
const dbMarker = '/databases/(default)/documents/';
if (msg.includes(dbMarker)) {
const docPath = msg.substring(msg.indexOf(dbMarker) + dbMarker.length, msg.indexOf('"', msg.indexOf(dbMarker)));
docsSeen.add(docPath);
}
});
db.collection('allDocs').onSnapshot(snapshot => {
...
}, error => {
...
});
```
And then in my console output:
```
Seen docs up to this point 12087
Seen docs up to this point 15934
values match true
Seen docs up to this point 15934
values match true
Seen docs up to this point 15934
values match true
```
which indicates that the Firestore backend keeps sending the same set of documents over and over to the client. In fact, when I changed the script to simply output the docPath of the received document, you can see them increment in the console until looping and starting over from the beginning.
One other oddity I noticed was that some of the documents received were not from the 'allDocs' collection but rather a subcollection, e.g. 'allDocs/<doc id>/subCollection/<sub doc id>', even though I'm only doing a .onSnapshot for allDocs.
It's pretty bold to claim that there's a bug in the backend but from what I'm looking at, it seems like the onSnapshot never completes (even after running it for 20 minutes), and from the console log, it looks like it'll never go beyond a certain point.