From: "Ravi Mistry via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Vaidas Pilkauskas <vaidas.pilkauskas@shopify.com>,
Patrick Steinhardt <ps@pks.im>,
"brian m. carlson" <sandals@crustytoothpaste.net>,
Ravi Mistry <rmistry@google.com>
Subject: [PATCH v5 0/5] http: exponential backoff, configurable status codes, and post_rpc() retries
Date: Wed, 25 Nov 2026 17:48:28 +0000 [thread overview]
Message-ID: <pull.2287.v5.git.1795628913.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2287.git.1793462224.gitgitgadget@gmail.com>
Commit 640657ffd0 (http: add support for HTTP 429 rate limit retries,
2026-03-17) added HTTP 429 retry support using http.maxRetries,
http.retryAfter, and http.maxRetryTime.
In practice, when running Git against hosting backends and reverse proxies
under high concurrency, four gaps remain:
1. Off-by-one retry count and Retry-After Trace2 timing: Because
http_request_recoverable() pre-decrements the retry counter
(--rate_limit_retries) in its loop condition, setting http.maxRetries=1
performs 0 retries (and N configured retries performs N-1 retries). In
addition, the Retry-After header is extracted after Trace2 logging has
already run, so the http/429-retry-after Trace2 event always logs -1.
2. No exponential backoff (and 0s default) when Retry-After is absent: When
a server does not send a Retry-After header, Git defaults
http.retryAfter to 0 (retrying immediately in a tight loop) and waits
the same fixed delay on every retry when configured. Doubling the delay
on each attempt and defaulting http.retryAfter to 10 seconds (10s, 20s,
40s, ...) gives overloaded servers breathing room while keeping
interactive commands reasonably responsive.
3. Transient 5xx errors cannot be retried: While service providers are
expected to return 429 when rate-limiting or overloaded, reverse
proxies, CDNs, client-side proxies, and servers also surface transient
connection drops, timeouts, or load shedding as 502, 503, or 504.
Because 5xx errors are not universally transient across all setups, 429
should remain the default, with an opt-in config to specify additional
status codes as a temporary workaround while underlying infrastructure
is fixed.
4. Read-only HTTP POST requests are not retried: Git's existing 429 retry
logic only covers HTTP GET requests (such as the initial /info/refs
handshake). However, the actual data transfer during fetch and clone, as
well as on-demand blob downloads in partial clones (during checkout,
diff, or blame), are sent as HTTP POST requests (/git-upload-pack) via
post_rpc(), which only retries authentication and immediately aborts on
429 or 5xx.
This 5-patch series addresses all four gaps:
* Patch 1/5 fixes the off-by-one retry count bug and extracts Retry-After
in finish_active_slot() before Trace2 logging runs.
* Patch 2/5 doubles http.retryAfter on each subsequent retry attempt
(capped at http.maxRetryTime) when Retry-After is absent.
* Patch 3/5 adds http.retryStatusCodes (and GIT_HTTP_RETRY_STATUS_CODES),
defaulting to "429", so environments can opt into retrying codes like
"429,502,503,504".
* Patch 4/5 extracts a shared http_retry_wait() helper and extends retry
support in post_rpc() to read-only services ("git-upload-pack" and
"git-upload-archive") without retrying "git-receive-pack" (git push),
while fixing a missing Content-Encoding: gzip header on retry.
* Patch 5/5 changes the default of http.retryAfter from 0 to 10 seconds so
Git does not immediately hammer a rate-limiting server when no
Retry-After header is provided.
Prior discussions:
* https://lore.kernel.org/git/20201012184806.166251-3-smcallis@google.com/
* https://lore.kernel.org/git/pull.2008.v6.git.1773752435.gitgitgadget@gmail.com/
Changes since v4 (thanks to Junio C Hamano for the review):
* Patches 1/5, 2/5, 5/5: Unchanged from v4.
* Patch 3/5: Documented in http.retryStatusCodes that an empty value (from
the configuration or the environment variable) disables retries for all
status codes instead of restoring the default, and that listing 401 or
404 has no effect. Added a test for the empty value.
* Patch 4/5: Cleared results before each run_one_slot() call in post_rpc()
and probe_rpc() so that a request that fails to start does not report the
status of a previous attempt.
Changes since v3 (thanks to Patrick Steinhardt for the review):
* Patches 1/5, 3/5, 4/5: Un-indented shell case arms in
t/lib-httpd/http-429.sh to match CodingGuidelines.
* Patches 2/5, 4/5: Changed the retry attempt counter from int to size_t.
* Patch 3/5: Documented in http.retryStatusCodes that providers are
expected to return 429 when rate-limiting or overloaded, and that
configuring additional status codes is a temporary workaround while
underlying provider or proxy infrastructure is fixed.
* Patch 4/5: Restricted retries in post_rpc() to read-only services
("git-upload-pack" and "git-upload-archive") so "git-receive-pack" (git
push) is not retried, documented the retried request types in
http.maxRetries, and added a test covering push.
* Patch 5/5: Inspected the Retry-After header via curl_easy_header() when
CURLINFO_RETRY_AFTER <= 0 so an explicit "Retry-After: 0" or past
HTTP-date retries immediately instead of falling back to the 10-second
default, restored the past HTTP-date test in t5584, and added a test for
"Retry-After: 0".
Changes since v2:
* Patches 1/5..4/5: Unchanged from v2.
* Added Patch 5/5 to default http.retryAfter to 10 seconds instead of 0
when Retry-After is absent (per feedback from Junio C Hamano and brian m.
carlson).
Changes since v1:
* Patch 1/4: Clarified in the commit message why the http_max_retries <= 0
check was moved after the retry loop.
* Patch 2/4: Passed http_max_retries - rate_limit_retries instead of adding
a separate attempt counter, and clarified the http.retryAfter and
http.maxRetryTime docs.
* Patch 3/4: Restored (Too Many Requests) and clarified
http.retryStatusCodes in the config docs, and moved the 400..599 range
check to the top of is_retryable_http_code().
* Patch 4/4: Added the attempt counter here when replacing
rate_limit_retries with http_retry_wait().
Ravi Mistry (5):
http: fix retry count and Retry-After timing
http: add exponential backoff without Retry-After
http: add http.retryStatusCodes config option
remote-curl: retry transient HTTP errors in post_rpc()
http: default http.retryAfter to 10 seconds
Documentation/config/http.adoc | 72 ++++++++---
git-curl-compat.h | 8 ++
http.c | 169 +++++++++++++++++++------
http.h | 12 +-
remote-curl.c | 84 +++++++------
t/lib-httpd/http-429.sh | 63 ++++++++--
t/t5584-http-429-retry.sh | 217 ++++++++++++++++++++++++++++++++-
7 files changed, 521 insertions(+), 104 deletions(-)
base-commit: 8d1b215c01512b9658d4525c54ff9b9245f9a7e8
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2287%2Frmistry%2Fhttp-exponential-retries-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2287/rmistry/http-exponential-retries-v5
Pull-Request: https://github.com/gitgitgadget/git/pull/2287
Range-diff vs v4:
1: d4d3407728 = 1: d4d3407728 http: fix retry count and Retry-After timing
2: fc5dbf8aea = 2: fc5dbf8aea http: add exponential backoff without Retry-After
3: 8dc66bfca4 ! 3: b7d25ce7d4 http: add http.retryStatusCodes config option
@@ Documentation/config/http.adoc: http.maxRetryTime::
+ 400..599 range) that should be retried up to `http.maxRetries`
+ times. Defaults to `429` (Too Many Requests). Can be overridden by
+ the `GIT_HTTP_RETRY_STATUS_CODES` environment variable.
++ An empty value, whether from the configuration or from the
++ environment variable, disables retries for all status codes; it
++ does not restore the default. HTTP 401 and 404 are handled
++ separately (as authentication and "not found" responses), so
++ listing them has no effect.
+ See also `http.maxRetries`, `http.retryAfter`, and
+ `http.maxRetryTime`.
++
@@ t/t5584-http-429-retry.sh: test_expect_success 'verify normal repository access
+ test_grep "The requested URL returned error: 502" err
+'
+
++test_expect_success 'empty http.retryStatusCodes disables retries' '
++ test_config http.maxRetries 3 &&
++ test_config http.retryAfter 0 &&
++ test_config http.retryStatusCodes "" &&
++ test_must_fail git ls-remote "$HTTPD_URL/http_429/empty-status-codes/none/repo.git" 2>err &&
++ test_grep "The requested URL returned error: 429" err &&
++ test_config http.retryStatusCodes "429,502" &&
++ test_must_fail env GIT_HTTP_RETRY_STATUS_CODES= \
++ git ls-remote "$HTTPD_URL/http_429/env-empty-status-codes/none/repo.git" 2>err &&
++ test_grep "The requested URL returned error: 429" err
++'
++
+test_expect_success 'http.retryStatusCodes retries configured 502, 503, and 504 errors' '
+ test_config http.maxRetries 3 &&
+ test_config http.retryAfter 1 &&
4: ca247f390c ! 4: 05ca9adf8a remote-curl: retry transient HTTP errors in post_rpc()
@@ Commit message
retrying a push POST after a 502 or 504 is not safe if the remote
already processed the request. Also defer reporting RPC errors until
retries are exhausted, and re-attach the "Content-Encoding: gzip" header
- when retrying a compressed request.
+ when retrying a compressed request. Clear the slot results before each
+ request so that a retried request that fails to start does not report
+ the status of the previous attempt.
Signed-off-by: Ravi Mistry <rmistry@google.com>
@@ remote-curl.c: static int probe_rpc(struct rpc_state *rpc, struct slot_results *
curl_easy_setopt(slot->curl, CURLOPT_WRITEDATA, &buf);
- err = run_slot(slot, results);
++ memset(results, 0, sizeof(*results));
+ err = run_one_slot(slot, results);
curl_slist_free_all(headers);
@@ remote-curl.c: retry:
- err = run_slot(slot, NULL);
- if (err == HTTP_REAUTH && !large_request) {
- http_reauth_prepare(0);
++ memset(&results, 0, sizeof(results));
+ err = run_one_slot(slot, &results);
+ if (!large_request && !rpc->any_written &&
+ (err == HTTP_REAUTH ||
5: 7d4335839d = 5: b6af8c5f92 http: default http.retryAfter to 10 seconds
--
gitgitgadget
next prev parent reply other threads:[~2026-11-25 17:48 UTC|newest]
Thread overview: 63+ 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
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-04 22:05 ` brian m. carlson
2026-11-05 0:10 ` Ravi Mistry
2026-11-05 17:45 ` Junio C Hamano
2026-11-05 22:32 ` brian m. carlson
2026-11-06 16:27 ` Ravi Mistry
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
2026-11-07 3:40 ` [PATCH v3 0/5] http: exponential backoff, configurable status codes, and post_rpc() retries Ravi Mistry via GitGitGadget
2026-11-07 3:40 ` [PATCH v3 1/5] http: fix retry count and Retry-After timing Ravi Mistry via GitGitGadget
2026-11-18 12:00 ` Patrick Steinhardt
2026-11-18 21:52 ` Ravi Mistry
2026-11-07 3:40 ` [PATCH v3 2/5] http: add exponential backoff without Retry-After Ravi Mistry via GitGitGadget
2026-11-18 12:00 ` Patrick Steinhardt
2026-11-18 21:53 ` Ravi Mistry
2026-11-07 3:40 ` [PATCH v3 3/5] http: add http.retryStatusCodes config option Ravi Mistry via GitGitGadget
2026-11-18 12:00 ` Patrick Steinhardt
2026-11-18 21:53 ` Ravi Mistry
2026-11-19 11:28 ` Patrick Steinhardt
2026-11-19 12:23 ` Ravi Mistry
2026-11-07 3:40 ` [PATCH v3 4/5] remote-curl: retry transient HTTP errors in post_rpc() Ravi Mistry via GitGitGadget
2026-11-18 12:01 ` Patrick Steinhardt
2026-11-18 21:53 ` Ravi Mistry
2026-11-07 3:40 ` [PATCH v3 5/5] http: default http.retryAfter to 10 seconds Ravi Mistry via GitGitGadget
2026-11-18 12:01 ` Patrick Steinhardt
2026-11-18 21:54 ` Ravi Mistry
2026-11-07 4:37 ` [PATCH v3 0/5] http: exponential backoff, configurable status codes, and post_rpc() retries Junio C Hamano
2026-11-10 3:58 ` Ravi Mistry
2026-11-19 15:57 ` [PATCH v4 " Ravi Mistry via GitGitGadget
2026-11-19 15:57 ` [PATCH v4 1/5] http: fix retry count and Retry-After timing Ravi Mistry via GitGitGadget
2026-11-24 22:23 ` Junio C Hamano
2026-11-19 15:58 ` [PATCH v4 2/5] http: add exponential backoff without Retry-After Ravi Mistry via GitGitGadget
2026-11-24 22:31 ` Junio C Hamano
2026-11-19 15:58 ` [PATCH v4 3/5] http: add http.retryStatusCodes config option Ravi Mistry via GitGitGadget
2026-11-24 22:44 ` Junio C Hamano
2026-11-25 15:13 ` Ravi Mistry
2026-11-19 15:58 ` [PATCH v4 4/5] remote-curl: retry transient HTTP errors in post_rpc() Ravi Mistry via GitGitGadget
2026-11-24 23:04 ` Junio C Hamano
2026-11-25 15:13 ` Ravi Mistry
2026-11-19 15:58 ` [PATCH v4 5/5] http: default http.retryAfter to 10 seconds Ravi Mistry via GitGitGadget
2026-11-24 23:04 ` [PATCH v4 0/5] http: exponential backoff, configurable status codes, and post_rpc() retries Junio C Hamano
2026-11-25 17:48 ` Ravi Mistry via GitGitGadget [this message]
2026-11-25 17:48 ` [PATCH v5 1/5] http: fix retry count and Retry-After timing Ravi Mistry via GitGitGadget
2026-11-25 17:48 ` [PATCH v5 2/5] http: add exponential backoff without Retry-After Ravi Mistry via GitGitGadget
2026-11-25 17:48 ` [PATCH v5 3/5] http: add http.retryStatusCodes config option Ravi Mistry via GitGitGadget
2026-11-25 17:48 ` [PATCH v5 4/5] remote-curl: retry transient HTTP errors in post_rpc() Ravi Mistry via GitGitGadget
2026-11-25 17:48 ` [PATCH v5 5/5] http: default http.retryAfter to 10 seconds Ravi Mistry via GitGitGadget
2026-11-25 19:04 ` [PATCH v5 0/5] http: exponential backoff, configurable status codes, and post_rpc() retries Junio C Hamano
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=pull.2287.v5.git.1795628913.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--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