-
Notifications
You must be signed in to change notification settings - Fork 2k
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 in ApolloServerPluginUsageReporting plugin #7639
Comments
Thanks for the great report, sorry it's taken me a week to get to this. I'll have a closer look tomorrow! |
@gabotechs have you had a chance to look at my PR and try out the built packages? |
Any progress on this issue? We have a memory leak and we are trying to identify where it is coming from too, but we have disabled the reporting and still see a memory spike. |
@juancarlosjr97 are you able to create a minimal reproduction? That's certainly interesting that you see the issue with reporting disabled, they may be unrelated. |
I will create one @trevor-scheer and share it. The issue has been narrowed down to many unique operations for the same query. query GetBestSellers($category1: ProductCategory) {
bestSellers(category: $category1) {
title
}
} query GetBestSellers($category2: ProductCategory) {
bestSellers(category: $category2) {
title
}
} The We have tested this behaviour on the Apollo v3 and Apollo v4, with all plugins disabled, and still the same behaviour. Also, profiling revealed that what is taking more memory from and continuously growing is the graphql library, specifically from the This might be another issue, and if it is, I will raise a separate issue for it if has not been raised already internally by Apollo by then. We have raised this internally with Apollo and the reference number is |
@juancarlosjr97 given what you've narrowed it down to so far this does seem unrelated, so a separate issue would be preferred. How sure are you that:
is relevant? Have you ruled out just "many unique operations" by itself? The "same query excluding variables" part would be a surprising twist to the issue. The |
@trevor-scheer If they're saying that they change the name of the variable ( |
@glasser right, I'm asking for clarification on exactly that. Like I don't think that it matters that the operation is entirely the same minus the variable name. It sounds more like a "many different operations" problem, more generally. I would be surprised if the issue was limited to that specific nuance. |
Right, I agree that the problem is likely "many different operations" — just that it might not be obvious that we treat those operations as distinct. |
Thank you for the replies @trevor-scheer and @glasser. We can confirm at this point, that the memory has been steady since we the consumer changed the query to be identified as the same operation using the same queries. I will work on reproducing the issue and when I have done it, I will raise another issue with all the details and a repository to clone and replicate the bug, as the memory is not getting released which is the problem |
@trevor-scheer and @glasser I created a project with instruction that shows the memory leak issue https://github.com/juancarlosjr97/apollo-graphql-federation-memory-leak. I am going to be raising another issue with all the details of the issue. |
Issue Description
We've been running Apollo server for a while in a couple of APIs, and we have always noticed a memory leak in both, which appeared to be linearly proportional to the number of requests handled by each API.
While investigating the memory leak, v8 heap snapshots where taken from the running servers at two different timestamps, with a distance of 6 hours. The latter heap snapshot was compared to the previous one in order to track what new objects are in the JS heap that where not 6 hours before, and there are thousands of new retained
Request
-like objects that reference the "usage-reporting.api.apollographql.com" host, and hundreds ofTLSSocket
new objects that reference this same host.Some objects that are leaking in the JS memory:
Request-like object
TLSSocket object
Here is a chart showing the memory usage of the last two days for one of the APIs:
The first left half of the chart (the first day) the Apollo server was running with the
ApolloServerPluginUsageReporting
enabled, and the memory kept increasing linearly, and the last half (the second day), exactly the same code was running but passing theApolloServerPluginUsageReportingDisabled
to the plugins, so that the usage reporting is disabled. In this last case no memory was being leaked.We are using
@apollo/server
with version4.3.0
Link to Reproduction
https://github.com/GabrielMusatMestre/apollo-server-memory-leak-repro
Reproduction Steps
Steps are described in the README.md of the reproduction repo.
This is not a reliable reproduction, as the memory leak might start being noticeable by running the server under heavy load for hours or days, and it needs a properly configured
APOLLO_KEY
andAPOLLO_GRAPH_REF
that will actually publish usage reports to Apollo.The text was updated successfully, but these errors were encountered: