Repository navigation
fix: pause upstream requests after HTTP 429 - #430
Conversation
|
@builderbot review |
1 similar comment
|
@builderbot review |
0679eff to
fde7e93
Compare
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
🤖 #440 coalesces concurrent cache misses more generally. It adds a shared spool used by every HTTP strategy, Git upload-pack and Git snapshot generation. Fetches outlive disconnecting clients, and error responses are shared only where RFC 9111 allows reuse. That overlaps with the coalescing half of this PR. It does not include the backoff after upstream 429 responses. If #440 lands, could the rate-limit cooldown be split into its own PR on top of it? |
When many clients request the same uncached object at once, each one
fetches it from upstream independently. That multiplies upstream load
and bandwidth exactly when an object is most in demand, and makes
upstream rate limits more likely. This matters most for large artefacts
and the upcoming OCI strategy, where a fleet of CI machines often pulls
the same blob at the same moment.
This change makes the first miss for a key start a single upstream
fetch, and every concurrent request for that key streams the response
while it is still downloading. It replaces the Git strategy's private
spool with a shared `internal/spool` package used by every HTTP
strategy, Git upload-pack and Git snapshot generation.
- A `spool.Registry` owns every in-flight fetch. Fetches run detached
from the requests that started them, so the cache still fills if every
client disconnects. They end at `fill-timeout` (default 30m) or when the
registry is closed after the server drains at shutdown.
- Successful responses are shared with concurrent requests. Error
responses are shared only where RFC 9111 allows a shared cache to reuse
them, for at most `error-window` (default 5s) from when the error's
headers arrive, so a burst of misses does not turn into a burst of
upstream errors. Each waiting request is checked against its own
credentials, `no-cache` directives and the response's `Vary` headers, so
an anonymous 404 cannot block an authorized download and a forced retry
always reaches upstream.
- Caches that can be read while they are written implement the new
optional `cache.PendingReader` interface on their `Writer`. Disk and
tiered caches do, so readers follow the cache write directly and the
response is stored once. Other backends fall back to a temporary file in
the spool directory.
- Each fill commits its cache write with `Writer.Commit`, which returns
cache failures to the strategy that owns the fill rather than logging
them inside the spool. A cache failure never fails an otherwise complete
response. Shared handler fills keep the handler's body verification and
revalidation timestamps, so a body that fails verification is still
served but never cached.
- HEAD misses are still forwarded upstream without caching. Range and
conditional misses are not coalesced, because they need a different
response from the shared one, and keep the existing miss path.
- If a shared response fails after its headers were sent, the connection
is aborted so clients cannot mistake a truncated body for a complete
one. Fills run outside the HTTP server's panic recovery, so an
`http.ErrAbortHandler` panic from reused handler code such as
`httputil.ReverseProxy` becomes a fill error instead of crashing the
process. This also fixes a Git bug where a failed spooled upload-pack
response was followed by a second, upstream response after headers had
been sent.
- Git snapshots are now generated once, directly into the cache, while
every waiting request streams them. The fill holds the repository's
snapshot lock from clone to commit, so it cannot overwrite a newer
periodic snapshot. If another snapshot job holds the lock, the fill
streams without caching.
Configuration is a new optional global block, documented in the README.
Leaving it out applies the defaults shown:
```hcl
spool {
dir = "${CACHEW_STATE}/spools"
fill-timeout = "30m"
error-window = "5s"
}
```
This overlaps with #430, which also coalesces HTTP misses. This PR
covers that part more broadly, but it does not include #430's backoff
after upstream 429 responses, which would need to land separately.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
f2116f6 to
628703b
Compare
|
@builderbot review |
1 similar comment
|
@builderbot review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5acd01ee37
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 98847538d6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d04784430
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
During load testing an upstream Maven repository rate limited cachew, and cachew kept forwarding misses to it, extending the block on the shared egress IP. The daemon's default HTTP transport now tracks a cooldown per origin (scheme, host and port) after a 429. During the cooldown, requests to that origin get a synthetic 429 with Retry-After and Cache-Control: no-store without contacting it. Cache hits and other origins are unaffected, and nothing is retried automatically. The cooldown uses a valid Retry-After (seconds or HTTP date) and falls back to the new global upstream-backoff setting (default 1m). NewHTTPClient now accepts a non-*http.Transport DefaultTransport, since the daemon wraps it. Co-authored-by: Cement <cabf7305c5a5bc19fd67db2823ee97e42039c363ef1c0c250e4b7a39af0bf470>
A 429 from one upstream of a handler now pauses every upstream request of that handler, including fallbacks, redirect targets and parallel chunks. Before, only the origin that returned 429 paused, and host fallbacks received the requests during the cooldown. Requests made outside the strategy handlers, such as Git, still pause per origin. Co-authored-by: Chain <492cad42391b4a5c84d831885f468e6f1699c0a8c39241f1c002235ece37ee69@buzz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Elizabeth Worstell <worstell@squareup.com>
Requests that a handler transform makes, such as the GitHub release metadata lookup, now share the handler's cooldown. A 429 from that lookup keeps Retry-After and is marked no-store. Co-authored-by: Chain <492cad42391b4a5c84d831885f468e6f1699c0a8c39241f1c002235ece37ee69@buzz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Elizabeth Worstell <worstell@squareup.com>
The 429 that starts a cooldown now has Cache-Control: no-store, so a downstream cache cannot keep it after the cooldown ends. Wrap the GitHub API error to satisfy wrapcheck. Co-authored-by: Chain <492cad42391b4a5c84d831885f468e6f1699c0a8c39241f1c002235ece37ee69@buzz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Elizabeth Worstell <worstell@squareup.com>
…wrapped NewHTTPClient now clones the standard library transport captured before cachewd wraps http.DefaultTransport, so cache clients keep 100 idle connections per host and do not share upstream 429 cooldowns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1d04784 to
258027f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 258027facf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // - No request transformation is performed | ||
| // - Standard error handling is used. | ||
| func New(client *http.Client, c cache.Cache, spools *spool.Registry) *Handler { | ||
| scope := httputil.NewBackoffScope(client.Transport) |
There was a problem hiding this comment.
Share one cooldown across all handlers in a strategy
Creating a fresh BackoffScope for every handler.New call does not provide the documented strategy-wide cooldown when one strategy owns multiple handlers. For example, NewOCI constructs separate blob and manifest handlers (internal/strategy/oci.go:119-128) and also has an unscoped pass-through path, so a 429 received while fetching a blob only cools the blob scope; an immediate manifest, tag-list, or referrers miss can still contact the same registry. The scope should be created once per strategy and shared by all of that strategy's upstream paths.
Useful? React with 👍 / 👎.
alecthomas
left a comment
There was a problem hiding this comment.
Only thing I would suggest is taking a look at https://pkg.go.dev/github.com/hashicorp/go-retryablehttp
But LGTM
When an upstream returns 429, cachewd stops sending upstream requests for that strategy until a cooldown ends. The pause covers the strategy's fallbacks, redirect targets and parallel chunk requests. During the cooldown, misses get a synthetic 429 with
Retry-AfterandCache-Control: no-store, and cachewd does not contact any upstream. Cache hits and other strategies are not affected. Requests made outside the strategy handlers, such as Git, pause per origin (scheme, host and port). Cachewd does not retry requests.The cooldown uses a valid upstream
Retry-After(seconds or HTTP date). If the header is missing or not valid, it uses the new globalupstream-backoffsetting (default1m). The backoff wrapshttp.DefaultTransport, and each handler tags its requests with its own cooldown scope. Cache clients made byNewHTTPClientkeep their own connection pool and do not use the cooldowns.🤖 Generated with Claude Code