From 399c04e810fa88e55fc06c5cfa6c78f25dd12f92 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Dec 2020 11:04:30 +0100 Subject: [PATCH] cloud-setup: fix handling cancellation of internal GET operation for EC2 provider There are two GCancellable at work: one is provided by the user during nmcs_provider_get_config(), and one is used internally for the individual HTTP GET requests. In _get_config_fetch_done_cb(), if the error reason is "cancelled", then it means that our internal iface_data->cancellable was cancelled. Probably because an error happend (like a timeout or the user cancelled the external GCancellable). In that case, we must not report that the task completed with a cancellation, because we need to preserve the error that was the original cause. --- clients/cloud-setup/nmcs-provider-ec2.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/clients/cloud-setup/nmcs-provider-ec2.c b/clients/cloud-setup/nmcs-provider-ec2.c index fb82914f38..7977eb640c 100644 --- a/clients/cloud-setup/nmcs-provider-ec2.c +++ b/clients/cloud-setup/nmcs-provider-ec2.c @@ -235,8 +235,16 @@ _get_config_fetch_done_cb(NMHttpClient *http_client, } } + /* If nm_utils_error_is_cancelled(error), then our internal iface_data->cancellable + * was cancelled, because the overall request failed. From point of view of the + * caller, this does not mean that a cancellation happened. It also means, our + * request overall is already about to fail. */ + nm_assert(!nm_utils_error_is_cancelled(error) || iface_data->error); + iface_data->n_pending--; - _get_config_task_maybe_return(iface_data, g_steal_pointer(&error)); + _get_config_task_maybe_return(iface_data, + nm_utils_error_is_cancelled(error) ? NULL + : g_steal_pointer(&error)); } static void