Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry mirrorlist/metalink downloads #159

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
retry mirrorlist/metalink downloads
Previously librepo did only one attempt to download the mirror
files.  And because especially Fedora metalink urls are nowadays
by default downloaded from 'mirrors.fedoraproject.org' host -
which is just a CNAME to set of DNS-load balanced proxies - it not
unlikely that librepo would ask some temporarily broken proxy.
Several attempts though will usually mean that librepo will
approach several different proxies.

In manual dnf-workflow, user would just re-try the whole dnf
command manually, but in build systems like Copr [1] this causes
severe problems and random build failures.

[1] https://pagure.io/fedora-infrastructure/issue/7987
  • Loading branch information
praiskup committed Jul 15, 2019
commit ac80f6c26ebbf358f68eb62e31306c22597dbbdc
26 changes: 24 additions & 2 deletions librepo/handle.c
Expand Up @@ -788,6 +788,28 @@ lr_handle_prepare_urls(LrHandle *handle, GError **err)
return TRUE;
}

static gboolean
lr_yum_download_url_retry(int attempts, LrHandle *lr_handle, const char *url,
int fd, gboolean no_cache, gboolean is_zchunk,
GError **err)
{
gboolean ret = FALSE;

for (int i = 1;; i++) {
ret = lr_yum_download_url(lr_handle, url, fd, no_cache, is_zchunk, err);
if (ret)
return ret;

if (i >= attempts)
return ret; // Caller to handle the last err

g_debug("%s: Attempt #%d to download %s failed: %s",
__func__, i, url, (*err)->message);
ftruncate(fd, 0);
g_clear_error (err);
}
}

static gboolean
lr_handle_prepare_mirrorlist(LrHandle *handle, gchar *localpath, GError **err)
{
Expand Down Expand Up @@ -845,7 +867,7 @@ lr_handle_prepare_mirrorlist(LrHandle *handle, gchar *localpath, GError **err)
}

url = lr_prepend_url_protocol(handle->mirrorlisturl);
if (!lr_yum_download_url(handle, url, fd, TRUE, FALSE, err)) {
if (!lr_yum_download_url_retry(3, handle, url, fd, TRUE, FALSE, err)) {
close(fd);
return FALSE;
}
Expand Down Expand Up @@ -960,7 +982,7 @@ lr_handle_prepare_metalink(LrHandle *handle, gchar *localpath, GError **err)
}

url = lr_prepend_url_protocol(handle->metalinkurl);
if (!lr_yum_download_url(handle, url, fd, TRUE, FALSE, err)) {
if (!lr_yum_download_url_retry(3, handle, url, fd, TRUE, FALSE, err)) {
close(fd);
return FALSE;
}
Expand Down