lightsystemdarkgreen
@ 261119.3

261119.3 877215a75c177459e37468e9e206a09e12ff0c2f A stopped git call kills its helpers, and the cache runs no auto gc

A git call whose context ended could hang: exec killed git itself, but a helper such as git-remote-https kept its stdout and stderr open, so Wait never returned. Each git call now runs in its own process group, the whole group is killed when the context ends, and the call stops waiting on the pipes five seconds later.

Git in the cache also runs with gc.auto=0 and maintenance.auto=false, which reach the git processes it starts. Every lazy fetch writes a pack, and past 50 packs a fetch started a detached full repack that no bound could stop.

On 2026-11-19 the two together held the public server at its memory limit for 13 hours: a repack of a 2.1G repo and a fetch whose call never returned.

reading declarations

doc/online-repos.md

@@ -80,7 +80,7 @@ A visitor learns nothing of the machine or of what others read. `/` says only ho  No page has a stop or bug button, nothing opens a browser, and any Host header is answered, since nothing local is there to protect. -`--disk` is required, since any visitor can make drvu clone. A clone, fetch or checkout stops once the repo outgrows it or after 10 minutes, so a forge that sends without end cannot fill the disk or hold a clone's place.+`--disk` is required, since any visitor can make drvu clone. A clone, fetch or checkout stops once the repo outgrows it or after 10 minutes, so a forge that sends without end cannot fill the disk or hold a clone's place. A stop kills every git process the fetch started. git in the cache runs no automatic gc or maintenance, since a full repack of a large repo can hold the server at its memory limit for hours.  A visitor can name any host, so drvu fetches only from hosts whose every address is on the open internet: never loopback, a private or link-local range, or carrier-grade NAT. git connects only to the addresses checked and follows no redirect, and listings check each address they connect to. A repo's `.git` is hidden, and a link out of a repo is refused without saying where it leads, whatever marker lies there. 

git.go

@@ -15,6 +15,7 @@ import ( 	"path/filepath" 	"regexp" 	"strings"+	"syscall" 	"time" ) @@ -22,6 +23,10 @@ import ( // crumbs: the command that makes it. const logLabel = "<(git log)" +// waitPipes is how long a git call whose context ended waits for its+// helpers to close its output+const waitPipes = 5 * time.Second+ // maxLog caps the commits a history page lists. const maxLog = 500 @@ -79,6 +84,13 @@ func gitRun(ctx context.Context, dir string, stdin io.Reader, progress func(stri 	if remote { 		pre = append(pre, "-c", "protocol."+webScheme+".allow=always", "-c", "credential.helper=", "-c", "core.askPass=", 			"-c", "core.hooksPath="+os.DevNull)+		// No automatic gc or maintenance: every lazy fetch of a page's+		// blobs writes a pack, and past gc.autoPackLimit's 50 packs a fetch+		// starts a full repack of the repo, detached, so no context ends it.+		// On a public server one held a 2.1G repo's unit at its memory+		// limit for 13 hours on 2026-11-19. -c reaches the git processes+		// this one starts, eg a lazy fetch.+		pre = append(pre, "-c", "gc.auto=0", "-c", "maintenance.auto=false") 		// git may fetch here, even for a page's blob, so a public server 		// checks where it would connect first. 		if publicNet.Load() {@@ -94,6 +106,18 @@ func gitRun(ctx context.Context, dir string, stdin io.Reader, progress func(stri 	args = append(append(pre, "-c", "core.fsmonitor=false", "-c", "core.quotePath=false", "--no-pager", "--literal-pathspecs"), args...) 	cmd := exec.CommandContext(ctx, "git", args...) 	cmd.Dir = dir+	// git runs helpers, eg git-remote-https for a fetch, which hold its+	// stdout and stderr. When ctx ends, kill the whole group, so no helper+	// outlives the bound, and stop waiting on the pipes after waitPipes+	// even if a helper still holds them.+	cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}+	cmd.Cancel = func() error {+		if err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL); err != syscall.ESRCH {+			return err+		}+		return os.ErrProcessDone+	}+	cmd.WaitDelay = waitPipes 	cmd.Stdin = stdin 	for _, kv := range os.Environ() { 		if !strings.HasPrefix(kv, "GIT_") && !strings.HasPrefix(kv, "SSH_ASKPASS=") {

git_test.go

@@ -1,12 +1,16 @@ package dirview  import (+	"context" 	"fmt" 	"os" 	"os/exec" 	"path/filepath"+	"strconv" 	"strings"+	"syscall" 	"testing"+	"time" )  func needGit(t *testing.T) {@@ -118,3 +122,51 @@ func TestGitRunsNoFsmonitor(t *testing.T) { 		t.Error("git ran the repo's fsmonitor") 	} }++// When a git call's context ends, the helpers git started die with it,+// and the call returns without waiting for them: on 2026-11-19 a fetch's+// git-remote-https outlived its bound by 13 hours.+func TestGitCancelKillsHelpers(t *testing.T) {+	_, dir := repoTree(t)+	pidFile := filepath.Join(t.TempDir(), "pid")+	ctx, cancel := context.WithTimeout(t.Context(), 300*time.Millisecond)+	defer cancel()+	start := time.Now()+	git(ctx, dir, "-c", "alias.hang=!echo $$ >"+pidFile+"; exec sleep 30", "hang")+	if d := time.Since(start); d >= waitPipes {+		t.Errorf("git returned after %v, want before the helper closed its pipes", d)+	}+	b, err := os.ReadFile(pidFile)+	if err != nil {+		t.Fatalf("helper never started: %v", err)+	}+	pid, _ := strconv.Atoi(strings.TrimSpace(string(b)))+	for i := 0; ; i++ {+		if syscall.Kill(pid, 0) == syscall.ESRCH {+			break+		}+		if i == 40 {+			t.Fatalf("helper %d still runs after the call returned", pid)+		}+		time.Sleep(50 * time.Millisecond)+	}+}++// git in the cache starts no automatic gc or maintenance, and the git+// processes it starts, eg a lazy fetch, inherit that.+func TestCacheGitRunsNoAutoGc(t *testing.T) {+	old := cacheRoot+	cacheRoot = t.TempDir()+	t.Cleanup(func() { cacheRoot = old })+	dir := filepath.Join(cacheRoot, "repo")+	if out, err := exec.Command("git", "init", "-q", dir).CombinedOutput(); err != nil {+		t.Fatalf("git init: %v\n%s", err, out)+	}+	out, err := git(t.Context(), dir, "-c", "alias.child=!git config --get gc.auto; git config --get maintenance.auto", "child")+	if err != nil {+		t.Fatal(err)+	}+	if got := string(out); got != "0\nfalse\n" {+		t.Errorf("child git sees gc.auto and maintenance.auto as %q, want \"0\\nfalse\\n\"", got)+	}+}