Memory leak on SSR after upgrading from 2.x to 3.3.13
See original GitHub issueRecently decided to upgrade apollo client from 2.6 to 3.3.13. After releasing it to production we saw huge memory usage increase on a server side. Rolling back to the old 2.6 version solved the problem.
Here is what happened in production while switched to 3.3.13 (tried to solve memory leak problem), gave up after 3 days and rolled back to 2.6:
Here is what we saw in the heapdumps (comparison view, filtered objects that were not deleted):
Seems like a lot of “Entry” instances are not garbage collected (deleted 0). Here is a dependency tree, maybe someone can help to see where the problem is:
Any help will be appreciated 🙏
Heapdumps:
- https://drive.google.com/file/d/10DnUSdyXN5q030bbcVXmgNpWWcUeVfy0/view?usp=sharing
- https://drive.google.com/file/d/1a05z2oty1i5foYvBkHK_T6uWdHwdPmw4/view?usp=sharing
Shortly about our setup:
- SSR (Node.js, React, apollo)
- Server side code is bundled with webpack
What we have tried:
resultCaching:false
config for the inmemory cache- Manuall call
client.stop()
client.clearStore
after each request. - Removed all
readFragment
calls. - Different node.js versions 12.8, 14.16
- Increased max old space size (heap size)
- Downgrade to apollo 3.1.3
Versions
- OS - alpine3.11
- @apollo/client - 3.3.13
- node.js - 14.16.0
- react - 16.8.2
- webpack 4.35.2
- graphql": 15.5.0
- graphql-tag": 2.12.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:40
- Comments:43 (9 by maintainers)
Top Results From Across the Web
Learn How to Debug the Cause of Memory Leak in SSR
After migrating a project in my charge to SSR, it made a sharp increase in heap memory and the Nodejs server was dead...
Read more >GitHub statistics for 3.5.2 (May 02, 2022) - Matplotlib
x (Raised macosx memory leak threshold). PR #22961: Raised macosx memory leak threshold. PR #22945: FIX: Handle no-offsets in collection datalim.
Read more >Hunting memory leaks in a server side rendered React ...
If you are using server side rendering (SSR) for your React application, you surely faced some issues at times. Even if you choose...
Read more >3 Troubleshoot Memory Leaks - Java - Oracle Help Center
After a garbage collection, if the Java application spends more than approximately 98% of its time performing garbage collection and if it is...
Read more >How to Detect and Fix Memory Leaks With Chrome DevTools
You have 2 free member-only stories left this month. ... Performance Timeline Record: before and after Memory Leak Fix (animation created by Rakia...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Tried
fetchPolicy: no-cache
this one reduces memory and CPU consumption significantly, but memory leak is still present 😢Currently, we have test setup with apollo3 with mirrored traffic from production, so I can check any hypothesis very quickly, any suggestion or help will be much appreciated!
The problem for us was that the
stringifyCanon
andstringifyCache
globals inobject-canon.js
grow without bound even when caching is disabled. The fix was to callApolloClient.clearStore
whenever we create the client: