-
Notifications
You must be signed in to change notification settings - Fork 897
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
Fix memory leak with ruby/require/autoload_paths #16837
Fix memory leak with ruby/require/autoload_paths #16837
Conversation
In ruby versions less than 2.5.0, it was found that if you have Pathname objects in the $LOAD_PATH instead of regular strings, it messes with ruby's internals and causes a memory leak. In most ruby applications, this wouldn't be much of an issue, but there are a significant number of deferred require statements that we do in manageiq that cause this to leak overtime. Further more, this seems to be an issue that presents itself even if the file has been loaded previously (mostly a no-op for require). Replication of this issue can be done using a simple ruby script: require 'pathname' require 'fileutils' puts Process.pid Dir.mkdir("foo") unless Dir.exists?("foo") $LOAD_PATH.unshift(Pathname.new("foo")) FileUtils.touch("empty.rb") 1500.times { 1500.times { require "empty" }; print "."; GC.start; } By simply running the application with the Pathnames converted to strings, this should be a proper and low cost workaround for us until it is patched in ruby or we update manageiq to >= ruby 2.5.0.
@miq-bot add_label bug, performance |
Checked commit NickLaMuro@4fb6f0b with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good find
Awesome sauce @NickLaMuro. |
config.autoload_paths << Rails.root.join("lib").to_s | ||
config.autoload_paths << Rails.root.join("lib", "services").to_s | ||
|
||
config.autoload_once_paths << Rails.root.join("lib", "vmdb", "console_methods.rb").to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want to link to the ruby bug here so we can fix this hack when ruby 2.3/2.4 are fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Good call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to merge anyway...the comment can be added when we add the spec we discussed in Gitter.
Edited your description to add manageiq-graphql 💕 |
@chrisarcand Thanks, you're the best! |
@miq-bot add_labels euwe/yes, fine/yes, gaprindashvili/yes |
Fix memory leak with ruby/require/autoload_paths (cherry picked from commit 193d031) https://bugzilla.redhat.com/show_bug.cgi?id=1536658
Gaprindashvili backport details:
|
Fix memory leak with ruby/require/autoload_paths (cherry picked from commit 193d031) https://bugzilla.redhat.com/show_bug.cgi?id=1536672
Fine backport details:
|
Fix memory leak with ruby/require/autoload_paths (cherry picked from commit 193d031) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1536692
Euwe backport details:
|
…ents Add comments and specs around the ruby 'require leak patch' (see #16837)
…oad_paths Fix memory leak with ruby/require/autoload_paths (cherry picked from commit 193d031) https://bugzilla.redhat.com/show_bug.cgi?id=1536672
…and_comments Add comments and specs around the ruby 'require leak patch' (see ManageIQ#16837) (cherry picked from commit 9bbd984)
In ruby versions less than 2.5.0, it was found that if you have
Pathname
objects in the$LOAD_PATH
instead of regular strings, it messes with ruby's internals and causes a memory leak.In most ruby applications, this wouldn't be much of an issue, but there are a significant number of deferred require statements that we do in
manageiq
that cause this to leak overtime. Further more, this seems to be an issue that presents itself even if the file has been loaded previously (mostly a no-op forrequire
).Replication of this issue can be done using a simple ruby script:
By simply running the application with the Pathnames converted to strings, this should be a proper and low cost workaround for us until it is patched in ruby or we update
manageiq
to >= ruby 2.5.0.This will also need to be done in the provider repos as well that happen to add to the
autoload_paths
in their engines as well. Should only be themanageiq-api
,manageiq-ui-classic
, and themanageiq-automation_engine
(PRs for those to come shortly, and will be linked below)Links
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1535720
TODO: Add links for the following
Steps for Testing/QA
Running the script above should replicate the issue on any system.
Additionally, we are testing this collection of patches on multiple appliances to confirm that the leak is removed.
Finally, once all these are merged (or by applying these patches locally), you can run a
bin/rails console
and confirm that nothing in the$LOAD_PATH
is aPathname
: