Bug 1307098

Summary: yum downloadonly does not reliably remove lock files
Product: Red Hat Enterprise Linux 6 Reporter: Andy Grimm <agrimm>
Component: yumAssignee: Valentina Mukhamedzhanova <vmukhame>
Status: CLOSED ERRATA QA Contact: Eva Mrakova <emrakova>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 6.7CC: emrakova, james.antill, jgoulding, ksrot, mkolaja, twiest
Target Milestone: rcKeywords: Patch, ZStream
Target Release: 6.8   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: yum-3.2.29-74.el6 Doc Type: Bug Fix
Doc Text:
Previously, a /var/run/yum.pid file was left on the disk after running the "yum --downloadonly" command. Consequently, under certain circumstances, the "yum" command failed because the yum utility incorrectly assumed that another instance of "yum" was already running. With this update, /var/run/yum.pid is correctly removed after running "yum --downloadonly", and the described problem no longer occurs.
Story Points: ---
Clone Of:
: 1337912 (view as bug list) Environment:
Last Closed: 2017-03-21 11:00:55 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1269194, 1277547, 1337912    

Description Andy Grimm 2016-02-12 17:16:17 UTC
Description of problem:
When "/usr/bin/yum -y --downloadonly update" is called, and there are packages to download, the process almost always leaves behind /var/run/yum.pid and rpmdb lockfiles.

The reason for this appears to be that yum calls sys.exit in this scenario, and sys.exit does not reliably trigger the __del__ method for the YumBase object, which is where all the unlocking/cleanup happen.

Relevant code from upstream, where this problem likely still exists:

sys,exit happens here:
http://yum.baseurl.org/gitweb?p=yum.git;a=blob;f=yum/__init__.py;h=84bea3eba2cf464f29666affb80ce658fc8fc074;hb=HEAD#l2627

__del__ method is here:
http://yum.baseurl.org/gitweb?p=yum.git;a=blob;f=yum/__init__.py;h=84bea3eba2cf464f29666affb80ce658fc8fc074;hb=HEAD#l235

Version-Release number of selected component (if applicable):
yum-3.2.29-69.el6.noarch

How reproducible:
Almost always

Steps to Reproduce:
1.  Log into a system for which there will be updates to download
2.  /usr/bin/yum -y --downloadonly update
3.  ls /var/run/yum.pid /var/lib/rpm/__*

Actual results:
yum.pid and rpmdb lockfiles are present


Expected results:
lock files should be removed prior to the yum process exiting.

Comment 2 Andy Grimm 2016-02-15 22:01:55 UTC
One update on this:  I realized that I may be wrong about the current function/purpose of the /var/lib/rpm/__db* files.  I was under the impression that those were lock files that would block subsequent transactions, but that does not seem to be the case in further tests.  Also, it seems that while calling self.closeRpmDB() does close those filehandles, it doesn't actually remove the files.  

Adding self.doUnlock() prior to the sys.exit definitely works to remove the PID file, though.

Comment 3 Andy Grimm 2016-02-16 21:12:16 UTC
It looks like upstream code closes these database well before the exit.  It appears to have been added in this commit:

http://yum.baseurl.org/gitweb?p=yum.git;a=commitdiff;h=05666dc9295fb433d1b081068dbe74e535cfc228

Comment 14 errata-xmlrpc 2017-03-21 11:00:55 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://rhn.redhat.com/errata/RHBA-2017-0702.html