From 3fe6101c0e72e81590dbaea2d0af1c757af03561 Mon Sep 17 00:00:00 2001 From: Joseph Marrero Date: Mon, 3 Apr 2023 19:04:57 -0400 Subject: [PATCH] ostree-fetcher-curl: add ENV VAR to retry requests This introduces the OSTREE_CURL_IO_RETRY environment variable that enables retries on requests that fail except when they fail with NOT_FOUND. We accomplish this by returning G_IO_ERROR_TIMED_OUT instead of G_IO_ERROR_FAILED as error code. --- src/libostree/ostree-fetcher-curl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libostree/ostree-fetcher-curl.c b/src/libostree/ostree-fetcher-curl.c index be88c4ef9f..e373a0f88d 100644 --- a/src/libostree/ostree-fetcher-curl.c +++ b/src/libostree/ostree-fetcher-curl.c @@ -304,6 +304,7 @@ check_multi_info (OstreeFetcher *fetcher) const char *eff_url; gboolean is_file; gboolean continued_request = FALSE; + gboolean should_retry; if (msg->msg != CURLMSG_DONE) continue; @@ -330,7 +331,14 @@ check_multi_info (OstreeFetcher *fetcher) } else { - g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, + /* When it is not a file and the OSTREE_CURL_IO_RETRY + * environment variable is set, we want to retry the request. + * We accomplish that by using G_IO_ERROR_TIMED_OUT. + */ + should_retry = g_getenv ("OSTREE_CURL_IO_RETRY") != NULL; + int g_io_error_code + = (is_file || !should_retry) ? G_IO_ERROR_FAILED : G_IO_ERROR_TIMED_OUT; + g_task_return_new_error (task, G_IO_ERROR, g_io_error_code, "While fetching %s: [%u] %s", eff_url, curlres, curl_easy_strerror (curlres)); _ostree_fetcher_journal_failure (req->fetcher->remote_name, eff_url,