Skip to content

Commit

Permalink
remote-curl: do not call run_slot repeatedly
Browse files Browse the repository at this point in the history
Commit b81401c (http: prompt for credentials on failed POST)
taught post_rpc to call run_slot in a loop in order to retry
a request after asking the user for credentials. However,
after a call to run_slot we will have called
finish_active_slot. This means we have released the slot,
and we should no longer look at it.

As it happens, this does not cause any bugs in the current
code, since we know that we are not using curl_multi in this
code path, and therefore nobody will have taken over our
slot in the meantime. However, it is good form to actually
call get_active_slot again. It also future proofs us against
changes in the http code.

We can do this by jumping back to a retry label at the top
of our function. We just need to reorder a few setup lines
that should not be repeated; everything else within the loop
is either idempotent, needs to be repeated, or in a path we
do not follow (e.g., we do not even try when large_request
is set, because we don't know how much data we might have
streamed from our helper program).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Oct 12, 2012
1 parent 188923f commit abf8df8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions remote-curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,18 @@ static int post_rpc(struct rpc_state *rpc)
return -1;
}

headers = curl_slist_append(headers, rpc->hdr_content_type);
headers = curl_slist_append(headers, rpc->hdr_accept);
headers = curl_slist_append(headers, "Expect:");

retry:
slot = get_active_slot();

curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");

headers = curl_slist_append(headers, rpc->hdr_content_type);
headers = curl_slist_append(headers, rpc->hdr_accept);
headers = curl_slist_append(headers, "Expect:");

if (large_request) {
/* The request body is large and the size cannot be predicted.
* We must use chunked encoding to send it.
Expand Down Expand Up @@ -528,9 +529,9 @@ static int post_rpc(struct rpc_state *rpc)
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);

do {
err = run_slot(slot);
} while (err == HTTP_REAUTH && !large_request && !use_gzip);
err = run_slot(slot);
if (err == HTTP_REAUTH && !large_request && !use_gzip)
goto retry;
if (err != HTTP_OK)
err = -1;

Expand Down

0 comments on commit abf8df8

Please sign in to comment.