Skip to content

Commit

Permalink
Merge pull request ostreedev#3216 from cgwalters/mirrorlist-retries
Browse files Browse the repository at this point in the history
curl: Also map HTTP errors for retries
  • Loading branch information
jmarrero authored Mar 19, 2024
2 parents 7fdc792 + 76ab862 commit b96b4ff
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/libostree/ostree-fetcher-curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ check_multi_info (OstreeFetcher *fetcher)

req = g_task_get_task_data (task);

gboolean retry_all = (!is_file && req->fetcher->opt_retry_all);

if (req->caught_write_error)
g_task_return_error (task, g_steal_pointer (&req->caught_write_error));
else if (curlres != CURLE_OK)
Expand All @@ -337,12 +339,9 @@ check_multi_info (OstreeFetcher *fetcher)
/* When it is not a file, we want to retry the request.
* We accomplish that by using G_IO_ERROR_TIMED_OUT.
*/
gboolean opt_retry_all = req->fetcher->opt_retry_all;
int g_io_error_code
= (is_file || !opt_retry_all) ? 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));
g_task_return_new_error (
task, G_IO_ERROR, retry_all ? G_IO_ERROR_TIMED_OUT : G_IO_ERROR,
"While fetching %s: [%u] %s", eff_url, curlres, curl_easy_strerror (curlres));
_ostree_fetcher_journal_failure (req->fetcher->remote_name, eff_url,
curl_easy_strerror (curlres));
}
Expand All @@ -362,12 +361,13 @@ check_multi_info (OstreeFetcher *fetcher)

if (!is_file && !(response >= 200 && response < 300) && response != 304)
{
GIOErrorEnum giocode = _ostree_fetcher_http_status_code_to_io_error (response);
GIOErrorEnum giocode
= _ostree_fetcher_http_status_code_to_io_error (response, retry_all);

if (req->idx + 1 == req->mirrorlist->len)
{
g_autofree char *response_msg
= g_strdup_printf ("Server returned HTTP %lu", response);
g_autofree char *response_msg = g_strdup_printf (
"While fetching %s: Server returned HTTP %lu", eff_url, response);
g_task_return_new_error (task, G_IO_ERROR, giocode, "%s", response_msg);
if (req->fetcher->remote_name
&& !((req->flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT) > 0
Expand Down
2 changes: 1 addition & 1 deletion src/libostree/ostree-fetcher-soup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ on_request_sent (GObject *object, GAsyncResult *result, gpointer user_data)
#endif
break;
default:
code = _ostree_fetcher_http_status_code_to_io_error (msg->status_code);
code = _ostree_fetcher_http_status_code_to_io_error (msg->status_code, FALSE);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libostree/ostree-fetcher-soup3.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ on_request_sent (GObject *object, GAsyncResult *result, gpointer user_data)
{
g_autofree char *uristring
= g_uri_to_string (soup_message_get_uri (request->message));
GIOErrorEnum code = _ostree_fetcher_http_status_code_to_io_error (status);
GIOErrorEnum code = _ostree_fetcher_http_status_code_to_io_error (status, FALSE);
{
g_autofree char *errmsg = g_strdup_printf ("Server returned status %u: %s", status,
soup_status_get_phrase (status));
Expand Down
7 changes: 4 additions & 3 deletions src/libostree/ostree-fetcher-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ _ostree_fetcher_should_retry_request (const GError *error, guint n_retries_remai
* a #GIOErrorEnum. This will return %G_IO_ERROR_FAILED if the status code is
* unknown or otherwise unhandled. */
GIOErrorEnum
_ostree_fetcher_http_status_code_to_io_error (guint status_code)
_ostree_fetcher_http_status_code_to_io_error (guint status_code, gboolean should_retry)
{
switch (status_code)
{
Expand All @@ -235,8 +235,9 @@ _ostree_fetcher_http_status_code_to_io_error (guint status_code)
case 408: /* SOUP_STATUS_REQUEST_TIMEOUT */
return G_IO_ERROR_TIMED_OUT;
case 500: /* SOUP_STATUS_INTERNAL_SERVER_ERROR */
return G_IO_ERROR_BUSY;
/* retries are always mapped to timeouts, see similar logic in the curl error handling */
return should_retry ? G_IO_ERROR_TIMED_OUT : G_IO_ERROR_BUSY;
default:
return G_IO_ERROR_FAILED;
return should_retry ? G_IO_ERROR_TIMED_OUT : G_IO_ERROR_FAILED;
}
}
2 changes: 1 addition & 1 deletion src/libostree/ostree-fetcher-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void _ostree_fetcher_journal_failure (const char *remote_name, const char *url,

gboolean _ostree_fetcher_should_retry_request (const GError *error, guint n_retries_remaining);

GIOErrorEnum _ostree_fetcher_http_status_code_to_io_error (guint status_code);
GIOErrorEnum _ostree_fetcher_http_status_code_to_io_error (guint status_code, gboolean retry_all);

G_END_DECLS

Expand Down

0 comments on commit b96b4ff

Please sign in to comment.