Repository navigation
Done
Description
Summary
When git-cache-proxy is PID 1 in a container (the Dockerfile ENTRYPOINT runs it with no init), orphaned git processes are reparented to it and never reaped. Zombies accumulate until the PID limit is hit; then git cannot be spawned and every request fails with 502.
Two sources
- Detached auto maintenance. Every successful
git fetch --prune(src/git.rs:748 at d7ec06c) ends withgit maintenance run --auto --quiet --detach, which daemonizes. One zombie per fetch, including background refreshes (samefetch_inner->run_upstreampath, src/git.rs:375). - Killed process groups. Upstream commands and
upload-packrun in their own process group (src/git.rs:621, :1049). On cancel or timeout,kill_group(src/git.rs:1404) kills the group; tokio reaps only the leader, and the descendants (git remote-https,index-pack,pack-objects) are left to PID 1. A dropped client request cancels the in-flight upstream fetch (feat(git): bound upstream lifetime and cancel work before shutdown drain #77), so this fires on every client disconnect during a fetch. feat(git): bound upstream lifetime and cancel work before shutdown drain #77 assumes "orphaned descendants are reaped by their OS parent", which does not hold when the proxy is PID 1.
In one production container, about 20 minutes after a restart, source 2 accounted for about two thirds of the zombies and source 1 for one third.
Reproduction
docker build -t gcp .
T=$(mktemp -d); cd $T
git init -q --bare up.git && git clone -q up.git w
(cd w && git commit -q --allow-empty -m a && git push -q origin HEAD:main)
chmod -R a+rX up.git
docker run -d --name gcp -v $T/up.git:/up/repo.git:ro -p 8080:8080 gcp \
--bind 0.0.0.0:8080 --upstream file:///up --fetch-ttl-seconds 1
for i in 1 2 3 4 5; do
(cd w && git commit -q --allow-empty -m x$i && git push -q origin HEAD:main)
sleep 1.2; git ls-remote http://127.0.0.1:8080/repo.git >/dev/null
done
docker exec gcp ps -o pid,ppid,stat,args # one "Z [git]" (PPID 1) per fetchSource 2: serve a repo of about 100 MB and kill git clone about 0.6 s in; each abort leaves a zombie. With docker run --init, both cases leave none.
Origin
Present since 26c8138 (initial scaffold): fetch --prune plus the init-less ENTRYPOINT. Background refresh does not cause it but raises the fetch rate; #77 made source 2 frequent.
Possible fixes
- Run under an init (
docker run --init, tini asENTRYPOINT, orshareProcessNamespace: trueon Kubernetes). Covers both sources; verified with a read-only rootfs, non-root user, andcap_drop: ALL, and SIGTERM still drains cleanly. - Set
gc.autoDetach=falseandmaintenance.autoDetach=falsefor upstream git (for example ingit_config_env, src/git.rs:1529). Removes source 1 only; maintenance then runs inside the fetch group, under its timeout. - Reaping in-process as PID 1 is possible but must not steal exit statuses from tokio's own child waits, so a plain
waitpid(-1)loop is unsafe.
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix(docker): run the proxy under tini to reap orphans