Bug 1781360 - dnf.Base.close() does not close hawkey.log filedescriptor
Summary: dnf.Base.close() does not close hawkey.log filedescriptor
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: dnf
Version: 8.4
Hardware: All
OS: Linux
unspecified
low
Target Milestone: rc
: 8.0
Assignee: Marek Blaha
QA Contact: Radek Bíba
URL:
Whiteboard:
Depends On: 1781364 1594016
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-12-09 21:00 UTC by Mike McLean
Modified: 2020-04-28 16:49 UTC (History)
9 users (show)

Fixed In Version: libdnf-0.39.1-2.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1594016
Environment:
Last Closed: 2020-04-28 16:49:06 UTC
Type: Bug
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2020:1823 None None None 2020-04-28 16:49:22 UTC

Description Mike McLean 2019-12-09 21:00:36 UTC
+++ This bug was initially created as a clone of Bug #1594016 +++

Description of problem:

Not sure if this is a dnf issue or father down, but:

#!/usr/bin/python3
import dnf
import psutil

proc = psutil.Process()
base = dnf.Base()
base.conf.assumeyes = True
base.conf.read()
for i in [1, 2, 3]:
    base.fill_sack(load_system_repo='auto')
    base.close()
    print(proc.open_files())


produces:

[popenfile(path='/var/lib/sss/mc/passwd', fd=3, position=0, mode='r', flags=557056), popenfile(path='/var/lib/sss/mc/group', fd=5, position=0, mode='r', flags=557056), popenfile(path='/var/tmp/dnf-orion-admin-75jop0p2/hawkey.log', fd=6, position=4834, mode='a', flags=33793)]
[popenfile(path='/var/lib/sss/mc/passwd', fd=3, position=0, mode='r', flags=557056), popenfile(path='/var/lib/sss/mc/group', fd=5, position=0, mode='r', flags=557056), popenfile(path='/var/tmp/dnf-orion-admin-75jop0p2/hawkey.log', fd=6, position=4880, mode='a', flags=33793), popenfile(path='/var/tmp/dnf-orion-admin-75jop0p2/hawkey.log', fd=7, position=4968, mode='a', flags=33793)]
[popenfile(path='/var/lib/sss/mc/passwd', fd=3, position=0, mode='r', flags=557056), popenfile(path='/var/lib/sss/mc/group', fd=5, position=0, mode='r', flags=557056), popenfile(path='/var/tmp/dnf-orion-admin-75jop0p2/hawkey.log', fd=6, position=4880, mode='a', flags=33793), popenfile(path='/var/tmp/dnf-orion-admin-75jop0p2/hawkey.log', fd=7, position=5014, mode='a', flags=33793), popenfile(path='/var/tmp/dnf-orion-admin-75jop0p2/hawkey.log', fd=8, position=5102, mode='a', flags=33793)]

Note the multiple open files of hawkey.log.

Version-Release number of selected component (if applicable):
python3-dnf-2.7.5-12.fc28.noarch

Related see https://github.com/ansible/ansible/pull/41810

--- Additional comment from David Wilson on 2018-06-22 03:33:52 UTC ---

Hi there,

This problem seems to be due to 'self._sack = None' in 'def reset()' being insufficient to clear out the last reference to the Sack, causing tp_dealloc() to call hy_sack_free() and subsequently close the file descriptor.

Triggering a manual 'gc.collection()' suggests the problem is also unrelated to a reference cycle within the graph of the Sack object itself, unless it has a missing or buggy tp_traverse implementation.

Please expose an explicit close() method on the Sack object, the existing API is unsafe as it conflates memory management and resource finalization, which always leads to fragile and surprising results

Related digging: https://github.com/dw/mitogen/issues/280#issuecomment-399307248

--- Additional comment from Ben Cotton on 2019-05-02 20:47:28 UTC ---

This message is a reminder that Fedora 28 is nearing its end of life.
On 2019-May-28 Fedora will stop maintaining and issuing updates for
Fedora 28. It is Fedora's policy to close all bug reports from releases
that are no longer maintained. At that time this bug will be closed as
EOL if it remains open with a Fedora 'version' of '28'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 28 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

--- Additional comment from Orion Poplawski on 2019-05-06 17:42:41 UTC ---

Still present with python3-dnf-4.2.5-1.fc29.noarch

--- Additional comment from Jaroslav Mracek on 2019-09-10 16:47:56 UTC ---

I created a patch: https://github.com/rpm-software-management/libdnf/pull/792

--- Additional comment from Jaroslav Mracek on 2019-10-19 15:39:08 UTC ---

Fixed in Fedora 30 - dnf-4.2.11

Comment 3 Marek Blaha 2019-12-18 11:59:55 UTC
The bug with leaking file descriptor has been fixed in upstream by following pull requests:

https://github.com/rpm-software-management/libdnf/pull/792
https://github.com/rpm-software-management/libdnf/pull/809

There is still one problem with the reproducer. The base.close() method is not designed to be called multiple times. You should use `reset()` method instead:

#!/usr/bin/python3
import dnf
import psutil

proc = psutil.Process()

base = dnf.Base()
base.conf.assumeyes = True
base.conf.read()
for i in [1, 2, 3]:
    base.fill_sack(load_system_repo='auto')
    base.reset(sack=True, repos=True, goal=True)
    print(proc.open_files())
base.close()

Comment 10 errata-xmlrpc 2020-04-28 16:49:06 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:1823


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