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

Memory Leak due to readFragment #3132

Closed
ryansydnor opened this issue Mar 9, 2018 · 4 comments
Closed

Memory Leak due to readFragment #3132

ryansydnor opened this issue Mar 9, 2018 · 4 comments
Labels
📚 good-first-issue Issues that are suitable for first-time contributors.

Comments

@ryansydnor
Copy link

ryansydnor commented Mar 9, 2018

Intended outcome:
When using readFragment against data that is already in the cache, node's memory usage should remain stable.

Actual outcome:
Our node server's memory usage spiked once we started using readFragment in a heavily trafficked part of our application:

image

How to reproduce the issue:


const ApolloClient = require('apollo-client').ApolloClient
const HttpLink = require('apollo-link-http').HttpLink;
const InMemoryCache = require('apollo-cache-inmemory').InMemoryCache;
const gql = require('graphql-tag');
const fetch = require('node-fetch');

const client = new ApolloClient({
  link: new HttpLink({
    uri: 'https://www.teacherspayteachers.com/graph/graphql',
    fetch
  }),
  cache: new InMemoryCache()
});

client.query({
  query: gql`
    query ProductTest {
      products(ids:[968647]) {
        id
        description
        name
      }
    }
  `,
}).then(data => leakMemory());

const leakMemory = () => {
  setInterval(() => {
      client.readFragment({
        id: 'Product:968647',
        fragment: gql`
          fragment Leak on Product {
            id
            name
          }
        `
      });
      console.log(process.memoryUsage());
  }, 5);
};

I've tracked the issue down to this line:

We are never getting cache hits despite using exactly the same fragment because I believe we are losing our equality reference due to object instantiation here:

const query: DocumentNode = {
.

Version

  • apollo-client@2.2.6

/label memory-leak

@ghost ghost added good first issue labels Mar 9, 2018
ryansydnor added a commit to ryansydnor/apollo-client that referenced this issue Mar 9, 2018
@ghost ghost added good first issue labels Mar 9, 2018
@jonmagic
Copy link

We're experiencing the same bug I think, I noticed while memory profiling:

cloudapp annotation 2018-03-30 at 10 20 06 am png

@edqd
Copy link

edqd commented Apr 18, 2018

Is it possible that what we're experiencing is a very similar/same bug, but without any usage of readFragment? Although we do use cacheRedirects.

Memory usage

screen shot 2018-04-18 at 11 27 09

Memory profiling

screen shot 2018-04-18 at 11 23 01

@hwillson hwillson added 📚 good-first-issue Issues that are suitable for first-time contributors. and removed good first issue labels May 10, 2018
@jakepusateri
Copy link

I think #3444 fixed this issue by removing the internal caches in this file. It should be in the next release of apollo-utilities, having been merged to master already.

@hwillson
Copy link
Member

Thanks for reminding us about this issue @jakepusateri. Yes, this should now be fixed and will be included in the release of apollo-client 2.3.2 this Tuesday (May 29th, 2018).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📚 good-first-issue Issues that are suitable for first-time contributors.
Projects
None yet
Development

No branches or pull requests

5 participants