Bug 1395234 - ResourceWarning: unclosed file <_io.TextIOWrapper name='.. >
Summary: ResourceWarning: unclosed file <_io.TextIOWrapper name='.. >
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Spacewalk
Classification: Community
Component: Clients
Version: 2.5
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Michael Mráka
QA Contact: Red Hat Satellite QA List
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-11-15 13:46 UTC by Pavel Studeník
Modified: 2019-07-12 11:40 UTC (History)
0 users

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-07-12 11:40:47 UTC


Attachments (Terms of Use)

Description Pavel Studeník 2016-11-15 13:46:33 UTC
Description of problem:
Warning during reading file in Python3.

Problem is construction of code. Missing call to close file. For example:

cert = open(cert_path).read()
...

f = open(cert_path)
cert = f.read()
f.close()

https://docs.python.org/3/whatsnew/3.2.html

A ResourceWarning is also issued when a file object is destroyed without having been explicitly closed. While the deallocator for such object ensures it closes the underlying operating system resource (usually, a file descriptor), the delay in deallocating the object could produce various issues,...


Version-Release number of selected component (if applicable):
osad-5.11.74-1.fc24.noarch

How reproducible:
always

Steps to Reproduce:
1. install osad and run it

Additional info:
>> /usr/sbin/osad --pid-file /var/run/osad.pid -N -v

2016-11-15 14:11:48 jabber_lib.__init__: 
/usr/share/rhn/osad/jabber_lib.py:358: ResourceWarning: unclosed file <_io.TextIOWrapper name='/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT' mode='r' encoding='ANSI_X3.4-1968'>
  cert = open(cert_path).read()
2016-11-15 14:11:49 jabber_lib.setup_connection: Connected to jabber server elisha.brq.redhat.com
/usr/share/rhn/osad/osad.py:209: ResourceWarning: unclosed file <_io.TextIOWrapper name='/etc/sysconfig/rhn/systemid' mode='r' encoding='ANSI_X3.4-1968'>
  self._systemid = open(self._systemid_file).read()
/usr/share/rhn/osad/osad.py:246: ResourceWarning: unclosed file <_io.TextIOWrapper name='/etc/sysconfig/rhn/systemid' mode='r' encoding='ANSI_X3.4-1968'>
  systemid = open(self._systemid_file).read()
2016-11-15 14:11:49 jabber_lib.process_forever: 
/usr/share/rhn/osad/osad.py:267: ResourceWarning: unclosed file <_io.TextIOWrapper name='/etc/sysconfig/rhn/systemid' mode='r' encoding='ANSI_X3.4-1968'>
  systemid = open(self._systemid_file).read()

Comment 1 Michael Mráka 2019-07-12 11:40:47 UTC
This issue seems to be fixed in current Spacewalk 2.9 client.
If you are still able to reproduce it please update the reproducer and reopen it.
Thanks.



# /usr/sbin/osad --pid-file /var/run/osad.pid -N -v
2019-07-12 11:37:36 jabber_lib.__init__: 
2019-07-12 11:37:37 jabber_lib.setup_connection: Connected to jabber server spacewalk.exemple.com
2019-07-12 11:37:38 jabber_lib.process_forever: 
2019-07-12 11:37:38 osad_client.run_rhn_check_async: executed /usr/sbin/rhn_check with pid 77


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