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
[IMPORTANT] Memory Leak issue with graphql 2.0.17 #4370
Comments
Hi! Yikes, sorry to hear it. I'd love to track this down and release a patch, but I can't find it locally. Could you run
Then, in a script or console:
In the meantime, I'll be taking a look myself! |
A couple of things by way of background:
Now that I look into it, I see this benchmark started retaining memory after #4311. But the trouble is, that PR changed the benchmark and the code, so it'll require some digging to figure out exactly what started that extra retained memory. Another thing is, re-enabling No answers yet, but I'm still digging! |
Update: if you comment out Are you using GraphQL::Dataloader? |
I'm just not finding any likely candidates 😖 Here's the diff between versions: Do any of the bits of changed code there sound like they might have to do with any features that you use in a special way? Maybe some change there had an unexpected effect on certain uses of the library that I didn't consider 😖 Even if the code changes themselves don't make sense, maybe it would give us a clue where to look further. |
Hi @rmosolgo, thanks for looking into this.
No, I don't. |
Thanks for sharing, @andytpp. A couple of things after reviewing that profile:
|
@rmosolgo Sorry for the delay, I couldn't make time until now. |
Thanks for sharing those. Weirdly, I wonder if some change to GraphQL-Ruby internals made graphql-client think that it needs to rebuild itself. Could you share any information about how you're using graphql-client? I don't work with that gem usually but I'll try to replicate the scenario if you could share anything about your setup. |
Hi @rmosolgo, thank you for your patience. Based on your suspicion, we have investigated further and discovered a bug that was causing the schema to be rebuilt with every call. To be specific, the schema loading is called in every query execution. Attached are the profilers before and after our fix. Please let me know if you need any additional information. |
Glad you got to the bottom of it! I would like to investigate a bit why it happened starting in 2.0.17, do you mind sharing any details about the bug you discovered or how to fix it? (I'm wondering if maybe it should have been supported by GraphQL-Ruby, or at least, if you don't mind sharing, someone else might benefit from your work if they run into the same trouble.) |
Sure, I'll try replicating the main parts, and I believe you can easily do the same. We use graphql-client to execute queries against Contentful, and we have a wrapper class for this purpose: module Services
class MyClient
#...
def execute(query, variables: {})
schema = ::GraphQL::Client.dump_schema(http_executor, context: context)
client = ::GraphQL::Client.new(
schema: schema,
execute: http_executor
)
client.allow_dynamic_queries = true
parsed_query = client.parse(query)
client.query(parsed_query, variables: variables, context: context)
end
#...
end
end When we ran profiling on this class with version 2.0.17, we encountered a memory issue, as shown in the following code: client = Services::MyClient.new(config: config)
query = <<~QUERY
some query
QUERY
client.execute(query) # First call
report = MemoryProfiler.report(allow_files: "graphql") do
10.times do |i|
client.execute(query)
end
end To resolve the issue, we ensured that schema loading does not occur inside the I hope this information is helpful. |
Describe the bug
After updating to graphql 2.0.17, the ruby processes running graphql just keep increasing memory usage linearly until OOM.
When goes back to graphql 2.0.16, everything is fine.
Versions
graphql
version: 2.0.17rails
: 6.0.6.1ruby
: 2.6.6The text was updated successfully, but these errors were encountered: