-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Investigate potential memory leaks in SSR scenarios #11242
Comments
Not sure if this is the right place to report this, but we're investigating a memory issue in our next.js server and one of the cause seems to be SSR + useLazyQuery. It looks like even if the options ssr: false is passed to useLazyQuery, the QueryInfo is added to the queries set of QueryManager in the function watchQuery, but since the query is never executed on the server side, it stays in the queries variable forever. As we use one single instance of ApolloClient, the queries variable of the QueryManager grows until OOM. |
@rflament Thank you for the report, I'll look into that!
Independently of the outcome of that - please never do that! You will end up mixing private data of multiple users. When you're doing SSR, please create a new instance of Apollo Client for every request! |
Thanks! In our case the data fetched on the SSR side do not depend on the user, we don't pass the cookies to the apollo client, so the fact that the cache would be reused in all requests seemed a good thing. |
I'd still recommend the single store per request, since (as you noticed), Apollo Client isn't really tested for potentially thousands of requests per second on one instance, but only for "normal application usage" scenarios. |
The beta is out, and we're now waiting for feedback to dial in the right default cache limits. For everyone who was following along: please give it a try and report back - you can find all the details in this blog post: https://www.apollographql.com/blog/apollo-3-9-beta-feature-spotlight-the-memory-story |
I confirm that creating a new client instance per request fixed the memory leak, thanks! |
Going to close this with the release of 3.9. |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
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. |
Over time, we had different reports of potential memory leaks in SSR scenarios.
I'm going to spike out for a while and try to create some benchmarks and test scenarios that allow us to detect such cases.
See this Milestone for a list of related Apollo Client PRs: https://github.com/apollographql/apollo-client/milestone/37
Related "external" PRs for visibility:
remove
method toTrie
benjamn/wryware#553Cache
instance/class user-configurable viaoptions.cache
benjamn/optimism#615Add configurable(superseded)WeakCache
implementation based onFinalizationRegistry
benjamn/optimism#599@wry/caches
package, exportingStrongCache
andWeakCache
benjamn/wryware#568External discussions: react-native-community/discussions-and-proposals#741
The text was updated successfully, but these errors were encountered: