RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1333157 - YumBase leaks memory
Summary: YumBase leaks memory
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: yum
Version: 7.4
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: rc
: ---
Assignee: Valentina Mukhamedzhanova
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On:
Blocks: 1335549
TreeView+ depends on / blocked
 
Reported: 2016-05-04 19:31 UTC by Jeff Ortel
Modified: 2016-05-30 11:58 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1335549 (view as bug list)
Environment:
Last Closed: 2016-05-30 11:58:07 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Reproducer (771 bytes, text/plain)
2016-05-04 19:43 UTC, Jeff Ortel
no flags Details
Patch to fix small memory leaks in yum with plugins (3.65 KB, patch)
2016-05-05 21:23 UTC, James Antill
no flags Details | Diff

Description Jeff Ortel 2016-05-04 19:31:30 UTC
Description of problem:

Running the test 100 times, shows an initial increase of 174 MB then a steady increase of 80 MB to 290 MB.  Or, ~800 KB per erase/install operation.  The following is the output of the attached reproducer.

________________
total kB          335140   27040   13560
total kB          529304  201124  183532
total kB          521636  193536  175944
total kB          524524  196400  178808
total kB          527952  199904  182312
total kB          530720  202668  185076
total kB          532500  204460  186868
total kB          535984  208016  190424
total kB          539360  211304  193712
total kB          543200  215056  197464
total kB          545504  217344  199752
total kB          548320  220112  202520
total kB          551136  223036  205444
total kB          553184  225052  207460
total kB          555232  227116  209524
total kB          557536  229568  211976
.....
.....
total kB          608112  280036  262444
total kB          608624  280568  262976
total kB          608112  280048  262456
total kB          608368  280228  262636
total kB          608880  280780  263188
total kB          608880  280868  263276
total kB          609392  281292  263700
total kB          610160  282064  264472
total kB          608880  280912  263320


Version-Release number of selected component (if applicable):

yum-3.4.3-505

How reproducible:

Always.

Steps to Reproduce:
1. Run the reproducer.
2.
3.

Actual results:

RSS grows.


Expected results:

No growth.

Additional info:

Comment 1 Jeff Ortel 2016-05-04 19:43:52 UTC
Created attachment 1153998 [details]
Reproducer

Comment 2 Jeff Ortel 2016-05-04 19:44:48 UTC
Suggest running:

# python reproducer.py | grep total

Comment 3 James Antill 2016-05-04 22:07:23 UTC
 I believe this is the "fix":

    diff --git a/yum/plugins.py b/yum/plugins.py
    index 6857626..fcdfac8 100644
    --- a/yum/plugins.py
    +++ b/yum/plugins.py
    @@ -160,7 +160,7 @@ class YumPlugins:
             self.cmdlines = {}
     
             # Call close handlers when yum exit's
    -        atexit.register(self.run, 'close')
    +        # atexit.register(self.run, 'close')
     
             # Let plugins register custom config file options
             self.run('config')


...which took way too long to debug :-o.

 In theory it's part of the plugin API, but we can probably just break it and any users can call atexit themselves (tmprepo is a notable one).

Comment 5 James Antill 2016-05-05 03:22:49 UTC
This is a cleaner patch which doesn't break the API, but won't leak if nobody uses the feature:

diff --git a/yum/plugins.py b/yum/plugins.py
index 6857626..e1e5270 100644
--- a/yum/plugins.py
+++ b/yum/plugins.py
@@ -160,7 +160,10 @@ class YumPlugins:
         self.cmdlines = {}
 
         # Call close handlers when yum exit's
-        atexit.register(self.run, 'close')
+        if self._pluginfuncs['close']:
+            self.verbose_logger.error(
+                _('One or more plugins uses "close" handling but should use atexit directly.'))
+            atexit.register(self.run, 'close')
 
         # Let plugins register custom config file options
         self.run('config')

Comment 6 Jeff Ortel 2016-05-05 16:10:49 UTC
James, Thanks for your attention on this!

I tested the patch using the reproducer and it is an improvement.  However still seeing RSS growth of 139004 KB / 100 (operations) = 139 KB per erase/install.

100 erase/install operations
__________________________________________
total kB          537052  194472  175804
total kB          545412  202836  184168
total kB          546616  204040  185372
total kB          552992  210416  191748
total kB          556720  214144  195476
total kB          562640  220064  201396
total kB          565328  222752  204084
total kB          569836  227260  208592
total kB          572352  229776  211108
total kB          575928  233352  214684
total kB          578768  236192  217524
total kB          582084  239508  220840
total kB          584816  242240  223572
total kB          586664  244088  225420
total kB          588200  245624  226956
total kB          591916  249340  230672
total kB          576644  234196  215528
total kB          578180  235732  217064
total kB          579204  236756  218088
total kB          580740  238292  219624
total kB          581508  239060  220392
total kB          583044  240596  221928
total kB          583812  241364  222696
total kB          584580  242132  223464
total kB          585604  243156  224488
total kB          586628  244180  225512
total kB          587908  245460  226792
total kB          589188  246740  228072
total kB          590212  247764  229096
total kB          591492  249044  230376
total kB          606548  264100  245432
total kB          609964  267516  248848
total kB          607828  265380  246712
total kB          609108  266660  247992
total kB          610644  268196  249528
total kB          611668  269220  250552
total kB          612436  269988  251320
total kB          613716  271268  252600
total kB          639768  297192  278524
total kB          642536  299960  281292
total kB          643740  301164  282496
total kB          645296  302720  284052
total kB          630032  287584  268916
total kB          630032  287584  268916
total kB          630544  288096  269428
total kB          633080  290632  271964
total kB          651608  309032  290364
total kB          651864  309404  290736
total kB          654252  311676  293008
total kB          653996  311424  292756
total kB          656436  313860  295192
total kB          657364  314788  296120
total kB          659700  317124  298456
total kB          660592  318016  299348
total kB          661520  318944  300276
total kB          661936  319360  300692
total kB          646404  303956  285288
total kB          646660  304212  285544
total kB          646404  303956  285288
total kB          666732  324156  305488
total kB          667996  325420  306752
total kB          669180  326604  307936
total kB          670476  327900  309232
total kB          671560  328984  310316
total kB          672484  329908  311240
total kB          672740  330164  311496
total kB          657928  315480  296812
total kB          657928  315480  296812
total kB          658440  315992  297324
total kB          658696  316128  297460
total kB          658952  316504  297836
total kB          659464  316888  298220
total kB          659464  317016  298348
total kB          659464  317016  298348
total kB          659464  317016  298348
total kB          659464  317016  298348
total kB          659976  317528  298860
total kB          659720  317272  298604
total kB          659976  317528  298860
total kB          659720  317272  298604
total kB          660232  317784  299116
total kB          660232  317784  299116
total kB          660744  318248  299580
total kB          660488  318040  299372
total kB          660744  318244  299576
total kB          661000  318552  299884
total kB          661512  319016  300348
total kB          661256  318808  300140
total kB          662024  319516  300848
total kB          661512  319064  300396
total kB          662024  319576  300908
total kB          661768  319320  300652
total kB          662024  319576  300908
total kB          670008  327560  308892
total kB          679964  337516  318848
total kB          680220  337772  319104
total kB          680220  337772  319104
total kB          679964  337516  318848
total kB          684288  341840  323172
total kB          684288  341840  323172

Comment 7 James Antill 2016-05-05 19:58:20 UTC
Ok, that was weird as I had it doing nothing for hundreds of runs.


Hmmm, setting init_plugins=False makes it not leak, is that true there?


Or *&^* this is ugly, I believe I know what it is, try this patch:

diff --git a/yum/plugins.py b/yum/plugins.py
index e1e5270..e00a7b4 100644
--- a/yum/plugins.py
+++ b/yum/plugins.py
@@ -15,6 +15,7 @@
 # Copyright 2005 Duke University
 
 import os
+import sys
 import glob
 import imp
 import warnings
@@ -276,13 +277,18 @@ class YumPlugins:
             self.verbose_logger.debug(_('Not loading "%s" plugin, as it is disabled'), modname)
             return
 
-        try:
+        #  If we are running a second YumBase() with the same plugins, then
+        # reloading the plugins leaks a bit or memory. So just take them.
+        if modname in sys.modules:
+            module = sys.modules[modname]
+        else:
+         try:
             fp, pathname, description = imp.find_module(modname, [dir])
             try:
                 module = imp.load_module(modname, fp, pathname, description)
             finally:
                 fp.close()
-        except:
+         except:
             if self.verbose_logger.isEnabledFor(logginglevels.DEBUG_4):
                 raise # Give full backtrace:
             self.verbose_logger.error(_('Plugin "%s" can\'t be imported') %



...I get hundreds of runs with no change again.

Comment 8 James Antill 2016-05-05 21:23:30 UTC
Created attachment 1154387 [details]
Patch to fix small memory leaks in yum with plugins

All in a single patch, I think this could pretty much go into el7 as is and will solve the problems without any other changes.

Comment 9 Jeff Ortel 2016-05-09 19:07:39 UTC
My initial report and numbers were based on observations running the reproducer on f23 which is really dnf.  Sorry for the confusion.

Running the reproducer on RHEL 7.2 with patch applied, I'm also not seeing any growth in RSS.  Although, even with the patch not applied, I'm not amble to reproduce on EL7.

yum-3.4.3-132.el7.noarch
____________________________
[root@el7 yum]# python /tmp/reproducer.py | grep total
total kB          339096   20244   13236
total kB          517468  102068   91868
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920
total kB          513268   98136   87920

Running the reproducer on RHEL 6.5 with patch applied I'm seeing growth.
yum-3.2.29-43.el6_5.noarch
____________________________
[root@jortel-el6 yum]# patch < /tmp/yum.patch 
patching file plugins.py
Hunk #1 succeeded at 161 (offset 1 line).
patching file plugins.py
Hunk #2 succeeded at 162 (offset 1 line).
Hunk #3 succeeded at 200 (offset -4 lines).
Hunk #4 succeeded at 264 (offset -14 lines).
[root@jortel-el6 yum]# python /tmp/reproducer.py | grep total
total kB          302996   17568   11380
total kB          412964   92056   82016
total kB          447112  121448  110492
total kB          479340  150972  139232
total kB          511304  180288  167132
total kB          543488  209912  196204
total kB          575696  239580  225068
total kB          607660  269048  253216
total kB          639888  298824  282116

Updated the reproducer as:

  yb = YumBase()
+ yb.preconf.init_plugins = False

with seemingly not affect.  Did I do this right?

James, what versions are you testing / working with?

Comment 10 James Antill 2016-05-10 17:10:46 UTC
I was just using upstream on Fedora, as it's easiest to test here. I assumed there would be no difference between that and the el7 version on el7, as there hadn't been when we'd previously had leaks due to circular references etc..

Comment 11 James Antill 2016-05-11 20:21:21 UTC
Also for el6 VSZ going up by 22Mb per. run almost certainly implies one of the older leaks, of the kind I'd expected to find. It shouldn't be hard to find the patch to backport if you need the fixes there (someone just needs to go looking for the missing weakref).


Note You need to log in before you can comment on or make changes to this bug.