Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to get aggregate result because the client is offline #7198

Closed
sellsjonathan opened this issue Apr 5, 2023 · 9 comments · Fixed by #7212
Closed

Failed to get aggregate result because the client is offline #7198

sellsjonathan opened this issue Apr 5, 2023 · 9 comments · Fixed by #7212
Assignees

Comments

@sellsjonathan
Copy link

sellsjonathan commented Apr 5, 2023

  • Browser version: Chrome 111.0.5563.146
  • Firebase SDK version: firebase 9.15
  • Firebase Product: firestore database
  • React Application compiles via Vite.

I wanted to start using the new aggregate queries, to be more efficient in my reads.

My project has collections of projects and tasks

I wanted to find the totals of tasks per project with the following query, through a forEach()

projectIds.forEach((projectId: string) => {
  const allTasksQuery = query(
	  firebase.documents(),
	  where('taskEmails', 'array-contains', encodedEmail),
	  where('project.uid', '==', projectId),
	  where('isLatestVersion', '==', true)
  );
  const promise = getCountFromServer(allTasksQuery)
	  .then((result) => {
		  const projectCount = result.data().count;
		  totalTasks[projectId] = projectCount;
	  })
	  .catch((err) => console.error('Error getting task Totals', err));
  allPromises.push(promise);
  });

NOTE: firebase.documents() is just a wrapper for this ref:

	const documents = () => collection(firestore, 'documents');

This works roughly 50% of the time, especially when coming from a page that has already recieved data back from firestore in a more convention getDoc or getDocs query. If I hard reload on the page that executes this query, as well as in other circumstances I receive the following error:

FirebaseError: Failed to get aggregate result because the client is offline.
image

Any help or clarification would be greatly appreciated. Thank-you.

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@ehsannas
Copy link
Contributor

ehsannas commented Apr 5, 2023

Thanks for reporting @sellsjonathan . I'll take a look.

@ehsannas ehsannas self-assigned this Apr 5, 2023
@ehsannas
Copy link
Contributor

@sellsjonathan Are you using enableMultiTabIndexedDbPersistence() in your code?

@ehsannas
Copy link
Contributor

Second question: Is the authenticated user changing for cases when you get the error?

@sellsjonathan
Copy link
Author

@ehsannas

Hey there, yes we do appear to be using enableMultiTabIndexedDbPersistence(), and the authenticated user is consistent for these cases. It is an authorized user landing on a page within the application.

@atsjo
Copy link

atsjo commented Apr 12, 2023

Getting the same error with my project, using sdk 9.19.1with enableMultiTabIndexedDbPersistence() configured via the new caching api. I can trigger it by opening a second tab with my web-page... I am also testing with a user already logged in...

@ehsannas
Copy link
Contributor

Thanks for confirming @sellsjonathan @atsjo. This appears to be a bug specific to count when multi-tab is enabled. I am actively working on a fix.

ehsannas added a commit that referenced this issue Apr 12, 2023
Fixes #7198.

A proper long-term solution for multi-tab should be implemented.
ehsannas added a commit that referenced this issue Apr 12, 2023
* Allow aggregations to work with multi-tab.

Fixes #7198.

A proper long-term solution for multi-tab should be implemented.

* Create .changeset/three-months-lie.md

* Improve the change log entry.

* Skip the relevant test.

* Skip the relevant test.
@sellsjonathan
Copy link
Author

Thanks @ehsannas , really appreciate your time and investigation into this. When do you think this will get released?

@ehsannas
Copy link
Contributor

The fix has been merged. It'll be available in the upcoming release (likely next week)

@firebase firebase locked and limited conversation to collaborators May 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants