Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
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 1814337

Summary: Failed to download metadata - Cannot download local file?
Product: Red Hat Enterprise Linux 8 Reporter: David Galloway <dgallowa>
Component: dnfAssignee: amatej
Status: CLOSED NOTABUG QA Contact: swm-qe
Severity: unspecified Docs Contact:
Priority: medium    
Version: 8.1CC: amatej, james.antill
Target Milestone: rcKeywords: Triaged
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-31 13:16:41 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:

Description David Galloway 2020-03-17 16:57:47 UTC
Description of problem:
I'm not sure how else to summarize this but I reimage baremetal in my test lab thousands of times a day.  I'm seeing this on CentOS and EPEL repos.  Initially, I thought I was running into issues with obtaining mirrorlists from CentOS or FedoraProject infra so I started using a local mirrorlist.  Maybe once or twice a day (out of thousands of yum transactions), I get Error: Failed to download metadata for repo XXX.

Even after switching to a local mirrorlist (https://github.com/ceph/ceph-cm-ansible/blob/master/roles/testnode/templates/mirrorlists/8/CentOS-AppStream-mirrorlist).

Version-Release number of selected component (if applicable):
$ dnf --version
4.2.7
  Installed: dnf-0:4.2.7-7.el8_1.noarch at Mon 16 Mar 2020 03:35:46 PM GMT
  Built    : CentOS Buildsys <bugs> at Thu 19 Dec 2019 03:44:23 PM GMT

  Installed: rpm-0:4.14.2-25.el8.x86_64 at Mon 16 Mar 2020 03:21:18 PM GMT
  Built    : CentOS Buildsys <bugs> at Fri 08 Nov 2019 10:56:14 PM GMT


How reproducible:
Not very.  I ran `sudo yum clean all; sudo rm -rf /var/cache/dnf/*; sudo yum -v install -y kernel` in a loop for hours and only got one error.

Actual results:
From dnf.log

2020-03-17T13:43:56Z DEBUG CentOS-AppStream: has expired and will be refreshed.
2020-03-17T13:43:56Z DEBUG CentOS-Base: has expired and will be refreshed.
2020-03-17T13:43:56Z DDEBUG Removing file /var/cache/dnf/epel-5592778e2c98aa9d/repodata/3318196d249b5dd1832057d7c15231bc5b569f43fe0f71d7b69ba52d6b1516e7-comps-Everything.x86_64.xml
2020-03-17T13:43:56Z DEBUG CentOS-Extras: has expired and will be refreshed.
2020-03-17T13:43:56Z INFO 41 files removed
2020-03-17T13:43:56Z DEBUG copr:copr.fedorainfracloud.org:ktdreyer:ceph-el8: has expired and will be refreshed.
2020-03-17T13:43:56Z DDEBUG Cleaning up.
2020-03-17T13:43:56Z DEBUG epel: has expired and will be refreshed.
2020-03-17T13:43:56Z DEBUG lab-extras: has expired and will be refreshed.
2020-03-17T13:43:56Z DEBUG repo: downloading from remote: CentOS-AppStream
2020-03-17T13:43:56Z DEBUG Cannot download 'file:///etc/yum.repos.d/CentOS-AppStream-mirrorlist': Cannot open /var/cache/dnf/CentOS-AppStream-45ddaf9e132058af/repodata/repomd.xml: No such file or directory.
2020-03-17T13:43:56Z ERROR Failed to download metadata for repo 'CentOS-AppStream'
2020-03-17T13:43:56Z SUBDEBUG
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 552, in load
    ret = self._repo.load()
  File "/usr/lib64/python3.6/site-packages/libdnf/repo.py", line 394, in load
    return _repo.Repo_load(self)
RuntimeError: Failed to download metadata for repo 'CentOS-AppStream'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 406, in fill_sack
    self._add_repo_to_sack(r)
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 136, in _add_repo_to_sack
    repo.load()
  File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 558, in load
    raise dnf.exceptions.RepoError(str(e))
dnf.exceptions.RepoError: Failed to download metadata for repo 'CentOS-AppStream'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 114, in cli_run
    cli.run()
  File "/usr/lib/python3.6/site-packages/dnf/cli/cli.py", line 1151, in run
    return self.command.run()
  File "/usr/lib/python3.6/site-packages/dnf/cli/commands/makecache.py", line 50, in run
    return self.base.update_cache(timer)
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 377, in update_cache
    self.fill_sack(load_system_repo=False, load_available_repos=True)  # performs the md sync
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 429, in fill_sack
    self.repos.all().disable()
  File "/usr/lib/python3.6/site-packages/dnf/lock.py", line 147, in __exit__
    os.unlink(self.target)
FileNotFoundError: [Errno 2] No such file or directory: '/var/cache/dnf/metadata_lock.pid'
2020-03-17T13:43:57Z CRITICAL [Errno 2] No such file or directory: '/var/cache/dnf/metadata_lock.pid'

Additional Information:
# cat /etc/yum.repos.d/CentOS-AppStream.repo
[CentOS-AppStream]
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
mirrorlist=file:///etc/yum.repos.d/CentOS-AppStream-mirrorlist
name=CentOS-$releasever - AppStream


# cat /etc/yum.repos.d/CentOS-AppStream-mirrorlist
https://download-cc-rdu01.fedoraproject.org/pub/centos/8.1.1911/AppStream/x86_64/os/
http://mirror.linux.duke.edu/pub/centos/8.1.1911/AppStream/x86_64/os/
http://packages.oit.ncsu.edu/centos/8.1.1911/AppStream/x86_64/os/
http://distro.ibiblio.org/centos/8.1.1911/AppStream/x86_64/os/

Comment 1 amatej 2020-03-30 13:17:05 UTC
I think I know whats happening here, I even managed to exactly reproduce it.

You probably have systemd dnf-makecache.timer running (I think its set up by default) which periodically runs `dnf makecache --timer`, and if you do your command `sudo yum clean all; sudo rm -rf /var/cache/dnf/*; sudo yum -v install -y kernel` at the same time while the makecache is running you delete the lock file in /var/cache/dnf/, both transactions run at the same time and everything breaks.

This would explain the very irregular occurrence since you have to hit the exact time the timer starts makecache.

Can you check if you have such a timer? If you do I would suggest disabling it in order to fix this, you clean the cache anyway in your command manually.

Comment 2 David Galloway 2020-03-30 19:08:30 UTC
Indeed I do!

[root@smithi094 ~]# systemctl status dnf-makecache.timer
● dnf-makecache.timer - dnf makecache --timer
   Loaded: loaded (/usr/lib/systemd/system/dnf-makecache.timer; enabled; vendor preset: enabled)
   Active: active (waiting) since Mon 2020-03-30 13:55:33 UTC; 5h 10min ago
  Trigger: Mon 2020-03-30 19:08:28 UTC; 2min 6s left

Mar 30 13:55:33 smithi094 systemd[1]: Started dnf makecache --timer.

I'll disable this service in our CI.  Thank you so much!

Comment 3 amatej 2020-03-31 13:16:41 UTC
Glad I could help.

I am going to close this as NOTABUG since it technically isn't a problem in dnf, but in case it turns out this wasn't the issue or it didn't help please reopen it.