You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.
We've identified memory leak in removeClientSetsFromDocument function. The problem is the query parameter can refer to identical DocumentNodes which are actually different objects having different references. That makes cache hits impossible and results in the removed Map growing constantly.
Seems the problem relates to apollographql/apollo-client#3444 - this PR addresses absolutely the same issue in apollo-client repository.
Steps to reproduce
Our setup looks as the following - we have 2 servers: a Web server and an API server. The Web server communicates to the API server using Apollo client, the Web server also uses apollo-link-state to maintain some cache. Apollo client, cache object, links are created and initialized on the Web server for each client request and supposed to be fully released after a request is processed.
I prepared a small demo reproducing the problem:
Create an empty project
Add dependencies to package.json and run yarn install
constexpress=require("express");constgql=require("graphql-tag");constApolloClient=require("apollo-client").ApolloClient;constInMemoryCache=require("apollo-cache-inmemory").InMemoryCache;constwithClientState=require("apollo-link-state").withClientState;// Create Express servervarapp=express();app.get('/',asyncfunction(req,res){// Cache object is unique for each requestconstcache=newInMemoryCache();// Initialize link stateconstlink=withClientState({
cache,defaults: {title: "",},resolvers: {Mutation: {updateTitle: (_,{ title },{ cache })=>{constdata={ title };cache.writeData({ data });returnnull;},},},});// Initialize GraphQL clientconstclient=newApolloClient({
cache,
link
});// Update App title in the local cacheawaitclient.mutate({variables: {title: "Test App"},mutation: gql` mutation UpdateTitle($title: String!) { updateTitle(title: $title) @client { title } }`,});// Respond to the client. All allocated // resources are supposed to be released once done.res.sendStatus(200);});// Start the serverapp.listen(3000,function(){});
Run the application node --inspect=0.0.0.0:9229 ./index.js
Take a heap snapshot in DevTools (you might want to run GC before)
Reload the page
Repeat steps 7-8 a few times
Inspect snapshots, you'll notice Array objects increased and retained for each page reload
Look for a Map object named removed in Retainers panel. That Map has as many items, as many times the page was loaded. These items will never be removed - it's basically the reason of the memory leak issue.
The text was updated successfully, but these errors were encountered:
We've identified memory leak in removeClientSetsFromDocument function. The problem is the query parameter can refer to identical DocumentNodes which are actually different objects having different references. That makes cache hits impossible and results in the removed Map growing constantly.
Seems the problem relates to apollographql/apollo-client#3444 - this PR addresses absolutely the same issue in apollo-client repository.
Steps to reproduce
Our setup looks as the following - we have 2 servers: a Web server and an API server. The Web server communicates to the API server using Apollo client, the Web server also uses apollo-link-state to maintain some cache. Apollo client, cache object, links are created and initialized on the Web server for each client request and supposed to be fully released after a request is processed.
I prepared a small demo reproducing the problem:
yarn install
node --inspect=0.0.0.0:9229 ./index.js
The text was updated successfully, but these errors were encountered: