Skip to content

Zombie git processes accumulate when the proxy runs as PID 1 #87

Done

Description

@profiling

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

  1. Detached auto maintenance. Every successful git fetch --prune (src/git.rs:748 at d7ec06c) ends with git maintenance run --auto --quiet --detach, which daemonizes. One zombie per fetch, including background refreshes (same fetch_inner -> run_upstream path, src/git.rs:375).
  2. Killed process groups. Upstream commands and upload-pack run 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 fetch

Source 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 as ENTRYPOINT, or shareProcessNamespace: true on Kubernetes). Covers both sources; verified with a read-only rootfs, non-root user, and cap_drop: ALL, and SIGTERM still drains cleanly.
  • Set gc.autoDetach=false and maintenance.autoDetach=false for upstream git (for example in git_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.

Activity

  1. added a commit that references this issue on Nov 25, 2026
    b70d7ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions