Skip to content

Commit

Permalink
upload-queue: don't exit when first error is encountered
Browse files Browse the repository at this point in the history
If we get a 4/500 error for some reason during a sync, the
upload program will currently quit at the first opportunity.
This can be annoying if doing a batch of updates, as syncs
halt altogether.  And we might get the error in the first
place because we have a batch and hit some ratelimits.

Introduce a version of http_post_lastpass_v that doesn't
die() in such cases and use it.  In a follow-up patch I'll
tweak the timeouts a bit so we handle this somewhat more
gracefully.

Signed-off-by: Bob Copeland <[email protected]>
  • Loading branch information
Bob Copeland committed Dec 31, 2015
1 parent ed892c0 commit 285833a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
25 changes: 22 additions & 3 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ char *http_post_lastpass(const char *page, const char *session, size_t *final_le
free(params.argv);
return result;
}
char *http_post_lastpass_v(const char *page, const char *session, size_t *final_len, char **argv)

char *http_post_lastpass_v_noexit(const char *page, const char *session, size_t *final_len, char **argv, int *curl_ret, long *http_code)
{
_cleanup_free_ char *url = NULL;
_cleanup_free_ char *postdata = NULL;
Expand Down Expand Up @@ -243,19 +244,37 @@ char *http_post_lastpass_v(const char *page, const char *session, size_t *final_
unset_interrupt_detect();

curl_easy_cleanup(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, http_code);
*curl_ret = ret;

if (ret != CURLE_OK) {
result.len = 0;
free(result.ptr);
result.ptr = NULL;
if (ret != CURLE_ABORTED_BY_CALLBACK)
die("%s.", curl_easy_strerror(ret));
} else if (!result.ptr)
result.ptr = xstrdup("");
if (final_len)
*final_len = result.len;

return result.ptr;
}

char *http_post_lastpass_v(const char *page, const char *session, size_t *final_len, char **argv)
{
char *result;
int ret;
long http_code;

result = http_post_lastpass_v_noexit(page, session, final_len,
argv, &ret, &http_code);

if (ret != CURLE_OK && ret != CURLE_ABORTED_BY_CALLBACK)
die("%s.", curl_easy_strerror(ret));

return result;
}


char *http_post_lastpass_param_set(const char *page, const char *session, size_t *final_len, struct http_param_set *param_set) {
return http_post_lastpass_v(page, session, final_len, param_set->argv);
}
1 change: 1 addition & 0 deletions http.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ char *http_post_lastpass(const char *page, const char *session, size_t *len, ...
char *http_post_lastpass_v(const char *page, const char *session, size_t *len, char **argv);
char *http_post_lastpass_param_set(const char *page, const char *session, size_t *len,
struct http_param_set *params);
char *http_post_lastpass_v_noexit(const char *page, const char *session, size_t *final_len, char **argv, int *curl_ret, long *http_code);

#endif
7 changes: 6 additions & 1 deletion upload-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ static void upload_queue_upload_all(const struct session *session, unsigned cons
char *name, *lock, *p;
bool do_break;
bool should_fetch_new_blob_after = false;
int curl_ret;
long http_code;

while ((entry = upload_queue_next_entry(key, &name, &lock))) {
size = 0;
Expand Down Expand Up @@ -196,7 +198,10 @@ static void upload_queue_upload_all(const struct session *session, unsigned cons
argv[size] = NULL;
for (int i = 0; i < 5; ++i) {
sleep(i * 2);
result = http_post_lastpass_v(argv[0], session->sessionid, NULL, &argv[1]);
result = http_post_lastpass_v_noexit(argv[0],
session->sessionid, NULL, &argv[1],
&curl_ret, &http_code);

if (result && strlen(result))
should_fetch_new_blob_after = true;
free(result);
Expand Down

0 comments on commit 285833a

Please sign in to comment.