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

Fix memory leak with ruby/require/autoload_paths #3266

Merged
merged 1 commit into from
Jan 18, 2018

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented Jan 17, 2018

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.

Links

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1535720

Steps for Testing/QA

Being tested in ManageIQ/manageiq#16837

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.
@NickLaMuro
Copy link
Member Author

@miq-bot add_label bug, performance

@miq-bot
Copy link
Member

miq-bot commented Jan 17, 2018

Checked commit NickLaMuro@5fc7b05 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🍪

@Fryguy Fryguy merged commit 62653f6 into ManageIQ:master Jan 18, 2018
@Fryguy Fryguy modified the milestones: bug, Sprint 78 Ending Jan 29, 2018 Jan 18, 2018
@Fryguy Fryguy self-assigned this Jan 18, 2018
@NickLaMuro
Copy link
Member Author

@miq-bot add_labels fine/yes, gaprindashvili/yes

simaishi pushed a commit that referenced this pull request Jan 19, 2018
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 8d3c0f3594202e15efde538000b21f02e3435774
Author: Jason Frey <fryguy9@gmail.com>
Date:   Thu Jan 18 12:33:27 2018 -0500

    Merge pull request #3266 from NickLaMuro/leak_fix_to_s_autoload_paths
    
    Fix memory leak with ruby/require/autoload_paths
    (cherry picked from commit 62653f63ab3b554184f2638636ef9274d13dad67)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1536658

simaishi pushed a commit that referenced this pull request Jan 19, 2018
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 6862353a73dd31fd0878a1f2aae5c2bc7414d4da
Author: Jason Frey <fryguy9@gmail.com>
Date:   Thu Jan 18 12:33:27 2018 -0500

    Merge pull request #3266 from NickLaMuro/leak_fix_to_s_autoload_paths
    
    Fix memory leak with ruby/require/autoload_paths
    (cherry picked from commit 62653f63ab3b554184f2638636ef9274d13dad67)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1536672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants