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

Having multiple watchQuery observables on the page causes an inifite number of rapid requests #6943

Closed
wassim-k opened this issue Aug 30, 2020 · 6 comments

Comments

@wassim-k
Copy link
Contributor

v3.1.x of apollo client introduced an odd issue in our software where having multiple watchQuery observables on the page causes it to make 10s of http requests per second an infinite number of times.

Intended outcome:
To make a single http request per watchQuery observable.

Actual outcome:
10s of requests are made to the server per second infinitely.

How to reproduce the issue:
I've created a minimal reporoduction of the issue, note I've mocked the http request but the original issue was happenning with a real backend.
https://stackblitz.com/edit/apollo-watch-query-infinite

Versions
System:
OS: Windows 10 10.0.18363
Binaries:
Node: 12.13.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.0 - ~\AppData\Roaming\npm\yarn.CMD
npm: 6.12.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 81.0.4044.92
Edge: Spartan (44.18362.449.0)

@dvakatsiienko
Copy link

Yes, I can confirm this issue but in a little bit different condition: using pollInterval, in case if multiple queries (pollInterval applied) are used on the same page.
I have 8 queries (pollInterval applied) on the same page which gives me an infinite querying loop very quickly.

@JesseZomer
Copy link

#6760 (comment) Here is some more info on something they changed in 3.1. If you set nextFetchPolicy: 'cache-first' it will stop.

I really think they should have communicated this a bit better, seeing the impact this can have on some servers

@wassim-k
Copy link
Contributor Author

@JesseZomer Thanks for shedding some more light on the problem.
Setting nextFetchPolicy seems to work for the initial request, but I've updated my reporoduction to contain a pollInterval which is used in our production app and that seems to trigger the infinite loop again.

@hubertlepicki
Copy link

Same issue. According to our tests, this has been introduced to our code base when we did upgrade from 3.1.3 to 3.1.4. The issue seems still present on 3.1.5, hasn't tested 3.2.0 yet.

@wassim-k
Copy link
Contributor Author

wassim-k commented Sep 17, 2020

I've created a new reporduction with 3.2.0 https://stackblitz.com/edit/apollo-watch-query-infinite-3-2
It works with nextFetchPolicy set to cache-first, even with pollInterval present.

I'm leaving this issue open because, imho, a configuration where the front-end fires an infinite number of requests rendering the backend irresponsive should not be possible under any circumstances, because the results are too severe in a production environment and is not always detectable in development.

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants