Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tokio = { version = "1", features = [
"sync",
"time",
] }
tokio-util = { version = "0.7", features = ["io"] }
tokio-util = { version = "0.7", features = ["io", "rt"] }
tower = { version = "0.5", features = ["limit"] }
tracing = "0.1"
tracing-appender = "0.2"
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,20 @@ Contributions welcome.
## License

[Apache-2.0](./LICENSE). Self-contained - no dependencies outside crates.io.

### Upstream operation lifetime

`--upstream-timeout-seconds` (`GITCACHEPROXY_UPSTREAM_TIMEOUT_SECONDS`, default
`3600`) bounds each clone, full-ref fetch and SHA backfill across attempts and
retry delays. The value must be positive and fit in a monotonic deadline.
Library users can set the same budget with `GitCache::with_upstream_timeout`.
The budget starts when the operation starts, after the repository lock is acquired.

SIGTERM and Ctrl-C reject new upstream work and cancel active commands, retry
backoff and repository lock waits before HTTP drain. Upstream owners kill process
groups on Unix and wait for the direct child before releasing repository locks.
Dropped requests also cancel their upstream owner. Library hosts call
`GitCache::shutdown` before draining HTTP and `wait_for_shutdown` after draining.
Active local upload-pack responses continue to drain. This does not impose a hard
shutdown bound on active uploads or blocking filesystem work. On non-Unix targets,
cancellation terminates only the direct child.
1 change: 1 addition & 0 deletions chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pointing at the Service.
| `clientAuth.allowHttp` | `false` | Accept a plain http validation endpoint (credentials in cleartext) |
| `clientAuth.signingKey.existingSecret` | `""` | Secret with the HMAC key signing LFS download grants; empty = a random key per pod |
| `clientAuth.signingKey.key` | `signing-key` | Key in that Secret |
| `config.upstreamTimeoutSeconds` | `3600` | Positive total seconds per upstream operation, including retries |
| `config.fetchTtlSeconds` | `10` | Skip upstream fetch if refreshed within this window (`0` = always) |
| `config.cacheMaxMb` | `0` | Cap on on-disk cache, MiB; evicts LRU idle mirrors (`0` = unlimited) |
| `config.maxConcurrentRequests` | `64` | Max concurrent in-flight requests (`0` = unlimited) |
Expand Down
5 changes: 5 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{- if or (not (regexMatch "^[1-9][0-9]*$" (toString .Values.config.upstreamTimeoutSeconds))) (le (int64 .Values.config.upstreamTimeoutSeconds) 0) }}
{{- fail "config.upstreamTimeoutSeconds must be a positive integer" }}
{{- end }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -63,6 +66,8 @@ spec:
value: {{ .Values.upstream | quote }}
- name: GITCACHEPROXY_CACHE_ROOT
value: /var/cache/git-cache-proxy
- name: GITCACHEPROXY_UPSTREAM_TIMEOUT_SECONDS
value: {{ .Values.config.upstreamTimeoutSeconds | quote }}
- name: GITCACHEPROXY_FETCH_TTL_SECONDS
value: {{ .Values.config.fetchTtlSeconds | quote }}
- name: GITCACHEPROXY_CACHE_MAX_MB
Expand Down
2 changes: 2 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ config:
# Skip the upstream fetch on info/refs if the mirror was refreshed within this
# many seconds; coalesces bursts of clones for one repo. 0 = always fetch.
fetchTtlSeconds: 10
# Total upstream command budget, including retries (positive seconds).
upstreamTimeoutSeconds: 3600
# Cap on total on-disk mirror cache, in MiB; evicts least-recently-used idle
# mirrors when exceeded. 0 = unlimited (no eviction). Set this whenever the
# cache volume is bounded.
Expand Down
21 changes: 21 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ pub struct Config {
#[arg(long, env = "GITCACHEPROXY_AUTH_TTL_SECONDS", default_value_t = 0)]
pub auth_ttl_seconds: u64,

/// Total seconds per upstream clone, full-ref fetch or SHA backfill,
/// including all attempts and retry delays. Must be positive.
#[arg(long, env = "GITCACHEPROXY_UPSTREAM_TIMEOUT_SECONDS", default_value = "3600",
value_parser = parse_upstream_timeout)]
pub upstream_timeout_seconds: u64,

/// Skip the upstream fetch on `info/refs` if the last fetch started within
/// this many seconds. Coalesces bursts of clones for the same repo. `0` =
/// always fetch (freshest, more upstream load).
Expand Down Expand Up @@ -302,10 +308,25 @@ pub struct Config {
pub log_format: LogFormat,
}

fn parse_upstream_timeout(value: &str) -> Result<u64, String> {
let seconds = value.parse::<u64>().map_err(|e| e.to_string())?;
crate::git::validate_upstream_timeout(std::time::Duration::from_secs(seconds))
.map_err(|e| e.to_string())?;
Ok(seconds)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn upstream_timeout_parser_matches_library_validation() {
assert_eq!(parse_upstream_timeout("3600").unwrap(), 3600);
for value in ["0", "-1", "18446744073709551615", "18446744073709551616"] {
assert!(parse_upstream_timeout(value).is_err(), "{value}");
}
}

#[test]
fn static_mode_never_conflicts() {
for provider in [
Expand Down
Loading
Loading