S08-05 - Push Limits
Purpose: Cleanup after a push that failed, the size cap of
landing.git, and the time and memory bounds of the git gateway.
Design
Section titled “Design”Cleanup after a failed push
Section titled “Cleanup after a failed push”Some late failures get past the pre-receive check (S08-04-push-checksS08-04-push-checks: Push ChecksThe checks that bound the memory and work of a push before git unpacks it: git's allocation limit, the pack scanner, and the pre-receive check.).
A lock file left by a crashed push, or an I/O error, still fails a ref
in update() after git moved the pack (X26-pre-receive-checkX26-pre-receive-check: Push checks before the quarantine landsCan a pre-receive check that Wraith Box owns, never the repository, refuse a push whose objects inflate past a cap, and repeat the ref checks git only runs in update(), so a refused push leaves nothing in landing.git…).
A receive-pack can also be killed: by the watchdog, a disconnect, or a
scanner refusal. It can then leave an objects/tmp_objdir-* quarantine
and *.lock files that repack and prune don’t remove. wb-hostd stops
git with SIGTERM, which lets git remove its quarantine, and with
SIGKILL after a grace period.
So wb-hostd cleans landing.git after every push in which not every
ref reported ok. That includes kills, disconnects, and scanner
refusals. It cleans while no other push to the repository runs:
- It removes
objects/tmp_objdir-*. - It removes
*.lockfiles underrefs/heads/wb/, andpacked-refs.lockat the repository’s root. - It runs
git repack -a -d -landgit prune --expire=now.
Landing lock
Section titled “Landing lock”A per-project lock in wb-hostd serializes the pushes to one landing
repository and its cleanup. Sessions share the repository
(FR05-parallel-sessionsFR05-parallel-sessions: Parallel sessionsSeveral sessions can run at once, in the same project and across projects.). Without the lock, a cleanup could prune a
concurrent push’s objects in the moment between leaving quarantine and
its ref update.
Landing size cap
Section titled “Landing size cap”A successful push can also leave objects that no ref reaches: extra
objects in its pack, and the bases that index-pack --fix-thin copies
in from export.git. A size cap per project bounds landing.git,
those objects included.
Before receive-pack starts, wb-hostd adds two sizes:
- everything under
landing.git, quarantine directories included; - the worst case of one push.
That worst case is a constant: the wire-byte cap plus the per-push cap
of the pack scanner (S08-04-push-checksS08-04-push-checks: Push ChecksThe checks that bound the memory and work of a push before git unpacks it: git's allocation limit, the pack scanner, and the pre-receive check.), 2 GiB with the current values.
It covers the pack itself, and the bases --fix-thin copies in, which
the per-push cap counts.
- When the sum is over the cap,
wb-hostdruns the repack and prune of “Cleanup after a failed push” first. - When the sum is still over the cap, it refuses the push. The message names the cap and the sum, and says to discard finished sessions.
A cap below the worst case of one push refuses every push, with that reason.
The cap is 4 GiB, twice the worst case. The user can change it with
landing_size_cap in the project’s settings.
wb land retries a fetch that fails while a repack runs.
Bounds
Section titled “Bounds”The size limit counts compressed bytes only (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.). Next to it, the git gateway has:
- a deadline and an idle timeout per connection;
- at most one
upload-packper session at a time; - at most one
receive-packper project at a time, under the landing lock; - a wall-clock watchdog that stops the git child.
For a push, the idle timeout is 60 s. The watchdog, which is also the connection’s deadline, is 5 minutes. Traffic in either direction counts as activity for the idle timeout.
While index-pack resolves the pack, receive-pack sends a keepalive
on the side band every receive.keepAlive seconds, git’s default of
5 s. So resolution time doesn’t trip the idle timeout.
The largest push measured took 33 to 56 s in receive-pack
(X28-git-alloc-limitX28-git-alloc-limit: git's allocation cap against delta bombsDoes GITALLOCLIMIT in receive-pack's environment make both host gits refuse each delta bomb of X26-pre-receive-check before allocating its result?). That was the Go repository’s whole history, with
the size limit raised to 1 GiB for the measurement. A push under the
scanner’s caps resolves at most 256 MiB.
The git gateway work sets the values for upload-pack.
The quarantine of one push holds at most:
- the pack, 256 MiB on the wire;
- the bases
--fix-thincopies in, counted in the 256 MiB per-push total.
That is about 512 MiB of disk. With one receive-pack per project at a
time, it is per project.
Memory
Section titled “Memory”GIT_ALLOC_LIMIT bounds each allocation git makes while it unpacks.
The pack scanner’s caps bound the total and the CPU time.
With receive.unpackLimit=1 and pack.threads=1, index-pack holds:
- its object table;
- its delta base cache (
core.deltaBaseCacheLimit); - a base and a result at a time;
- under
--strict, one fsck object record for each object, and for each ID a tree or commit names.
One tree or commit of up to 100 MiB can name millions of IDs. That part can add a few hundred MiB (security review of PR116PR116 (merged): docs(spikes): X28-git-alloc-limit result, yes with conditionsResult of spike X28-git-alloc-limit: yes, with conditions., not measured).
GIT_ALLOC_LIMIT also bounds those records. Git keeps them in one hash
table of 8-byte slots, which it doubles with xcalloc when it is half
full. The largest table under the limit has 8,388,608 slots (64 MiB).
So a push that names more than about 4.2 million distinct IDs fails
with git’s fatal: line. This is read from grow_object_hash in git
2.56.0, and not measured.
The peaks measured under a 100 MiB cap:
- 207 MiB for large deltas (X26-pre-receive-checkX26-pre-receive-check: Push checks before the quarantine landsCan a pre-receive check that Wraith Box owns, never the repository, refuse a push whose objects inflate past a cap, and repeat the ref checks git only runs in update(), so a refused push leaves nothing in landing.git…);
- 146 MiB for a million objects of 3 bytes in 12 MiB (X28-git-alloc-limitX28-git-alloc-limit: git's allocation cap against delta bombsDoes GITALLOCLIMIT in receive-pack's environment make both host gits refuse each delta bomb of X26-pre-receive-check before allocating its result?).
The conformance suite checks these measurements again (C08-gitC08-git: GitThe test cases for the git round trip: the transport, the pack scanner and the pre-receive check, git's own limits behind them, and the data scope of what a session gets from the host repository.).
Decisions
Section titled “Decisions”A size cap on landing.git
Section titled “A size cap on landing.git”- Why: a successful push can leave objects that no ref reaches. Without a cap the repository grows.
- Decided: B41-git-data-scopeB41-git-data-scope: Which git data may reach the guest, and how far does the host trust its own git?Serve the guest from a host-side export repository holding only the session's branch, scan carried-in files, clean remote URLs, and require a minimum git version., item 6.
The cap is eight times the worst case of one push.
- Why: the worst case follows from the 256 MiB wire-byte and per-push caps (B102-git-alloc-limitB102-git-alloc-limit: Can git itself refuse a push that asks for too much memory, so the pack scanner gets simpler?Yes, with conditions.).
Status: Draft