From: Junio C Hamano <gitster@pobox.com>
To: "Ravi Mistry via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,
Vaidas Pilkauskas <vaidas.pilkauskas@shopify.com>,
Patrick Steinhardt <ps@pks.im>,
"brian m. carlson" <sandals@crustytoothpaste.net>,
Ravi Mistry <rmistry@google.com>
Subject: Re: [PATCH 4/4] remote-curl: retry transient HTTP errors in post_rpc()
Date: Tue, 03 Nov 2026 06:47:28 -0800 [thread overview]
Message-ID: <xmqqh5hyas5b.fsf@gitster.g> (raw)
In-Reply-To: <52819accc894e760a0fd06730d20f46cc8da9914.1793462224.git.gitgitgadget@gmail.com> (Ravi Mistry via GitGitGadget's message of "Sat, 31 Oct 2026 15:57:04 +0000")
"Ravi Mistry via GitGitGadget" <gitgitgadget@gmail.com> writes:
> diff --git a/http.c b/http.c
> index 950e2bbffa..36b559e596 100644
> --- a/http.c
> +++ b/http.c
> @@ -2476,6 +2476,34 @@ static long handle_rate_limit_retry(long slot_retry_after, int attempt)
> }
> }
>
> +int http_retry_wait(long http_code, long slot_retry_after, int attempt)
> +{
> + long retry_delay;
> +
> + if (http_max_retries <= 0)
> + return -1;
> + if (attempt > http_max_retries) {
> + trace2_data_string("http", the_repository,
> + "http/429-error", "retries-exhausted");
> + return -1;
> + }
> + retry_delay = handle_rate_limit_retry(slot_retry_after, attempt);
> + if (retry_delay < 0)
> + return -1;
> + if (retry_delay > 0) {
> + if (http_code == 429)
> + warning(_("rate limited, waiting %ld seconds before retry"),
> + retry_delay);
> + else
> + warning(_("HTTP %ld, waiting %ld seconds before retry"),
> + http_code, retry_delay);
> + trace2_data_intmax("http", the_repository,
> + "http/retry-sleep-seconds", retry_delay);
> + sleep(retry_delay);
> + }
> + return 0;
> +}
This code looks familiar. Beautifully extracted from ...
> static int http_request_recoverable(const char *url,
> void *result, int target,
> struct http_get_options *options)
> @@ -2483,7 +2511,6 @@ static int http_request_recoverable(const char *url,
> static struct http_get_options empty_opts;
> int i = 3;
> int ret;
> - int rate_limit_retries = http_max_retries;
> int attempt = 0;
>
> if (!options)
> @@ -2506,9 +2533,8 @@ static int http_request_recoverable(const char *url,
> }
>
> while ((ret == HTTP_REAUTH && --i) ||
> - (ret == HTTP_RATE_LIMITED && http_max_retries > 0 &&
> - rate_limit_retries-- > 0)) {
> - long retry_delay = -1;
> + (ret == HTTP_RATE_LIMITED &&
> + !http_retry_wait(options->http_code, options->retry_after, ++attempt))) {
> /*
> * The previous request may have put cruft into our output stream; we
> * should clear it out before making our next request.
> @@ -2533,35 +2559,15 @@ static int http_request_recoverable(const char *url,
> default:
> BUG("Unknown http_request target");
> }
> - if (ret == HTTP_RATE_LIMITED) {
> - retry_delay = handle_rate_limit_retry(options->retry_after, ++attempt);
> - if (retry_delay < 0)
> - return HTTP_ERROR;
> -
> - if (retry_delay > 0) {
> - if (options->http_code == 429)
> - warning(_("rate limited, waiting %ld seconds before retry"),
> - retry_delay);
> - else
> - warning(_("HTTP %ld, waiting %ld seconds before retry"),
> - options->http_code, retry_delay);
> - trace2_data_intmax("http", the_repository,
> - "http/retry-sleep-seconds", retry_delay);
> - sleep(retry_delay);
> - }
> - } else if (ret == HTTP_REAUTH) {
> + if (ret == HTTP_REAUTH)
> http_reauth_prepare(1);
> - }
... existing code around here. It always feels good to see that an
introduction of a new function is accompanied by replacing many
lines of existsing code with a call to the new function.
Thanks.
next prev parent reply other threads:[~2026-11-03 14:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 15:57 [PATCH 0/4] http: exponential backoff, configurable status codes, and post_rpc() retries Ravi Mistry via GitGitGadget
2026-10-31 15:57 ` [PATCH 1/4] http: fix retry count and Retry-After timing Ravi Mistry via GitGitGadget
2026-11-03 1:03 ` Junio C Hamano
2026-11-03 19:05 ` Ravi Mistry
2026-10-31 15:57 ` [PATCH 2/4] http: add exponential backoff without Retry-After Ravi Mistry via GitGitGadget
2026-11-03 13:21 ` Junio C Hamano
2026-11-03 19:05 ` Ravi Mistry
2026-10-31 15:57 ` [PATCH 3/4] http: add http.retryStatusCodes config option Ravi Mistry via GitGitGadget
2026-11-03 13:41 ` Junio C Hamano
2026-11-03 19:06 ` Ravi Mistry
2026-10-31 15:57 ` [PATCH 4/4] remote-curl: retry transient HTTP errors in post_rpc() Ravi Mistry via GitGitGadget
2026-11-03 14:47 ` Junio C Hamano [this message]
2026-11-03 18:57 ` [PATCH v2 0/4] http: exponential backoff, configurable status codes, and post_rpc() retries Ravi Mistry via GitGitGadget
2026-11-03 18:57 ` [PATCH v2 1/4] http: fix retry count and Retry-After timing Ravi Mistry via GitGitGadget
2026-11-03 18:57 ` [PATCH v2 2/4] http: add exponential backoff without Retry-After Ravi Mistry via GitGitGadget
2026-11-03 18:57 ` [PATCH v2 3/4] http: add http.retryStatusCodes config option Ravi Mistry via GitGitGadget
2026-11-03 20:56 ` Junio C Hamano
2026-11-03 18:57 ` [PATCH v2 4/4] remote-curl: retry transient HTTP errors in post_rpc() Ravi Mistry via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqh5hyas5b.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=ps@pks.im \
--cc=rmistry@google.com \
--cc=sandals@crustytoothpaste.net \
--cc=vaidas.pilkauskas@shopify.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox