git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/4] remote-curl: retry transient HTTP errors in post_rpc()

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 3, 2026, 14:47 UTC
Message-ID
<xmqqh5hyas5b.fsf@gitster.g>
In-Reply-To
<52819accc894e760a0fd06730d20f46cc8da9914.1793462224.git.gitgitgadget@gmail.com>
"Ravi Mistry via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 35 quoted lines
> 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 ...
Show 47 quoted lines
>  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.
Previous: Ravi Mistry via GitGitGadgetNext: Ravi Mistry via GitGitGadget
Message 9 of 14 in “http: exponential backoff, configurable status codes, and post_rpc() retries”
  1. 0/4 http: exponential backoff, configurable status codes, and post_rpc() retriesRavi Mistry via GitGitGadget, Oct 31, 2026
  2. 1/4 http: fix retry count and Retry-After timingRavi Mistry via GitGitGadget, Oct 31, 2026
  3. Junio C HamanoNov 3, 2026
  4. 2/4 http: add exponential backoff without Retry-AfterRavi Mistry via GitGitGadget, Oct 31, 2026
  5. Junio C HamanoNov 3, 2026
  6. 3/4 http: add http.retryStatusCodes config optionRavi Mistry via GitGitGadget, Oct 31, 2026
  7. Junio C HamanoNov 3, 2026
  8. 4/4 remote-curl: retry transient HTTP errors in post_rpc()Ravi Mistry via GitGitGadget, Oct 31, 2026
  9. Junio C HamanoNov 3, 2026
  10. 0/4 http: exponential backoff, configurable status codes, and post_rpc() retriesRavi Mistry via GitGitGadget, Nov 3, 2026
  11. 1/4 http: fix retry count and Retry-After timingRavi Mistry via GitGitGadget, Nov 3, 2026
  12. 2/4 http: add exponential backoff without Retry-AfterRavi Mistry via GitGitGadget, Nov 3, 2026
  13. 3/4 http: add http.retryStatusCodes config optionRavi Mistry via GitGitGadget, Nov 3, 2026
  14. 4/4 remote-curl: retry transient HTTP errors in post_rpc()Ravi Mistry via GitGitGadget, Nov 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.