Skip to content

Commit abf8df8

Browse files
peffgitster
authored andcommitted
remote-curl: do not call run_slot repeatedly
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 188923f commit abf8df8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

remote-curl.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,17 +444,18 @@ static int post_rpc(struct rpc_state *rpc)
444444
return -1;
445445
}
446446

447+
headers = curl_slist_append(headers, rpc->hdr_content_type);
448+
headers = curl_slist_append(headers, rpc->hdr_accept);
449+
headers = curl_slist_append(headers, "Expect:");
450+
451+
retry:
447452
slot = get_active_slot();
448453

449454
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
450455
curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
451456
curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
452457
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "");
453458

454-
headers = curl_slist_append(headers, rpc->hdr_content_type);
455-
headers = curl_slist_append(headers, rpc->hdr_accept);
456-
headers = curl_slist_append(headers, "Expect:");
457-
458459
if (large_request) {
459460
/* The request body is large and the size cannot be predicted.
460461
* We must use chunked encoding to send it.
@@ -528,9 +529,9 @@ static int post_rpc(struct rpc_state *rpc)
528529
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
529530
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
530531

531-
do {
532-
err = run_slot(slot);
533-
} while (err == HTTP_REAUTH && !large_request && !use_gzip);
532+
err = run_slot(slot);
533+
if (err == HTTP_REAUTH && !large_request && !use_gzip)
534+
goto retry;
534535
if (err != HTTP_OK)
535536
err = -1;
536537

0 commit comments

Comments
 (0)