aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-03-15 06:23:19 +0200
committerSergey Poznyakoff <gray@gnu.org>2018-03-15 07:23:28 +0200
commit557ac31167d217b19efab8b8cfbd0a97a044a4b7 (patch)
treeff459bf3cfd9dab2f06687ab459bc507de453f26
parent649a04b9deec5d111e735bc47c37adca7e76f39e (diff)
downloadeclat-557ac31167d217b19efab8b8cfbd0a97a044a4b7.tar.gz
eclat-557ac31167d217b19efab8b8cfbd0a97a044a4b7.tar.bz2
Minor changes
* src/util.c (eclat_send_request): Fix the AWS error string. Print a warning before sleeping. Fix memory leak.
-rw-r--r--src/util.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/util.c b/src/util.c
index 9f8533f..3ada220 100644
--- a/src/util.c
+++ b/src/util.c
@@ -227,23 +227,27 @@ eclat_send_request(struct ec2_request *orig, struct grecs_node **ret_tree)
char *url;
CURLcode res;
int ret = 0;
- struct curl_slist *headers = NULL;
+ struct curl_slist *headers;
struct eclat_io *io;
time_t endtime;
unsigned long tts, t;
+ struct grecs_node *xmltree = NULL;
+ void *sim;
- io = eclat_io_init(0);
- if (!io) {
- err("cannot initialize IO structure");
- return -1;
- }
-
endtime = time(NULL) + max_retry_time;
- tts = 1;
+ tts = 2;
do {
struct grecs_node *node;
+ struct ec2_request *req;
+
+ io = eclat_io_init(0);
+ if (!io) {
+ err("cannot initialize IO structure");
+ return -1;
+ }
+
/* Prepare the request */
- struct ec2_request *req = eclat_request_dup(orig);
+ req = eclat_request_dup(orig);
if (req->flags & EC2_RF_POST) {
eclat_request_finalize(orig);
curl_easy_setopt(io->curl, CURLOPT_POST, 1);
@@ -257,6 +261,7 @@ eclat_send_request(struct ec2_request *orig, struct grecs_node **ret_tree)
curl_easy_setopt(io->curl, CURLOPT_URL, url);
debug(ECLAT_DEBCAT_MAIN, 1, ("using URL: %s", url));
free(url);
+ headers = NULL;
if (req->headers) {
struct grecs_list_entry *ep;
struct grecs_txtacc *acc;
@@ -298,12 +303,13 @@ eclat_send_request(struct ec2_request *orig, struct grecs_node **ret_tree)
else {
res = curl_easy_perform(io->curl);
if (res == CURLE_OK) {
- *ret_tree = eclat_io_finish(io);
+ xmltree = eclat_io_finish(io);
} else {
err("CURL: %s", curl_easy_strerror(res));
ret = 1;
}
}
+ eclat_io_free(io);
curl_slist_free_all(headers);
eclat_request_free(req);
@@ -311,21 +317,23 @@ eclat_send_request(struct ec2_request *orig, struct grecs_node **ret_tree)
if (ret)
break;
- node = grecs_find_node(*ret_tree,
- ".Response.Errors.Error.Code");
+ node = grecs_find_node(xmltree, ".Response.Errors.Error.Code");
if (!node)
break;
if (node->type != grecs_node_stmt
- || node->v.value->type == GRECS_TYPE_STRING) {
+ || node->v.value->type != GRECS_TYPE_STRING) {
err("unexpectedly formatted error code");
break;
}
- if (strcmp(node->v.value->v.string,
- "Client.RequestLimitExceeded"))
+ if (strcmp(node->v.value->v.string, "RequestLimitExceeded"))
break;
- t = random() % tts;
+ grecs_tree_free(xmltree);
+ xmltree = NULL;
+
+ t = random() % tts + 1;
+ warn("request limit exceeded; sleeping for %lu seconds", t);
sleep(t);
if (tts < max_retry_sleep) {
tts <<= 1;
@@ -333,9 +341,8 @@ eclat_send_request(struct ec2_request *orig, struct grecs_node **ret_tree)
tts = max_retry_sleep;
}
} while (time(NULL) < endtime);
-
- eclat_io_free(io);
-
+
+ *ret_tree = xmltree;
return ret;
}

Return to:

Send suggestions and report system problems to the System administrator.