{"thread":{"id":"66618","subject":"maintenance: stale maintenance.lock after the detached child is killed silently disables auto-maintenance (more likely since 2.55)","startedAt":"2026-10-21T10:16:48Z","lastAt":"2026-10-21T10:16:48Z","messageCount":1,"participants":["Masaya Kazama"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"555712","messageId":"CAEdWB0ChxOZUszwDVqWY3jdvGpNtV9NRTG8_X1-f2PX9QnJQTw@mail.gmail.com","threadId":"66618","inReplyTo":null,"subject":"maintenance: stale maintenance.lock after the detached child is killed silently disables auto-maintenance (more likely since 2.55)","fromName":"Masaya Kazama","fromEmail":"miyaokamiyao@gmail.com","sentAt":"2026-10-21T10:16:48Z","receivedAt":"2026-10-21T10:16:48Z","isPatch":false,"sender":{"key":"miyaokamiyao@gmail.com","avatar":null},"body":"[Resending as plain text; the first attempt was rejected by vger for\ncontaining an HTML part. Sorry for the duplicate to those on Cc.]\n\nHi,\n\nSince 6e95b07e5f (builtin/maintenance: fix locking with \"--detach\",\n2026-05-13), the detached \"git maintenance\" child owns\nobjects/maintenance.lock until its background tasks finish. If that\nchild is killed in a way that skips the tempfile cleanup (SIGKILL,\npower loss), the lock stays forever. Every later\n\"git maintenance run --auto\" then finds the lock and returns without\nrunning anything and without any message, so auto-maintenance stops\nfor good and nobody notices.\n\nThe stale lock itself was reported in 2024 [1], where Stolee called it\n\"unfortunately a common occurrence\". What is new is that 6e95b07e5f\nextends the window in which the lock is held from the foreground phase\nto the whole background run, so a kill during the (possibly long)\nbackground tasks now leaves the lock behind. Before 6e95b07e5f the\nparent removed the lock when it exited right after daemonizing.\n\nReproduction (git 2.56.0 on macOS; same FIFO trick as Taylor's test in\nthe \"fix locking with --detach\" discussion [2]):\n\n    git init -q repro && cd repro\n    git commit -q --allow-empty -m base\n    git config maintenance.auto false\n    git remote add origin /does/not/exist\n    git config remote.origin.uploadpack \\\n        \"echo \\$PPID >\\\"$PWD/fetch.pid\\\" && cat \\\"$PWD/fifo\\\"\"\n    mkfifo fifo\n\n    git maintenance run --task=prefetch --detach\n    while ! test -s fetch.pid; do sleep 0.1; done\n    daemon=$(ps -o ppid= -p \"$(cat fetch.pid)\" | tr -d ' ')\n\n    kill -9 \"$daemon\"\n    : >fifo\n    ls .git/objects/maintenance.lock      # still there\n\n    GIT_TRACE2_EVENT=\"$PWD/trace\" \\\n        git -c maintenance.loose-objects.auto=1 \\\n        maintenance run --auto --task=loose-objects\n    grep -c '\"region_enter\".*\"category\":\"maintenance\"' trace   # 0\n\n    git maintenance run --no-quiet --task=pack-refs\n    # warning: lock file '.git/objects/maintenance' exists,\n    #          skipping maintenance\n\nAfter \"rm .git/objects/maintenance.lock\" the same --auto run enters one\nmaintenance region. With Apple Git 2.50.1 (before 6e95b07e5f) the lock\nis already gone while the detached child runs, so killing it leaves\nnothing behind.\n\nHow I hit it: in one large partial clone (blob:none, ~425 branches)\nthe lock was created on 2026-06-30, a few minutes after I upgraded to\n2.55.0, and stayed until I found it on 2026-10-21. I do not know what\nkilled the detached child; no git crash reports exist for that day.\nDuring those four months a GUI tool fetched the repository every\nminute; the pack count grew to 3,550 and the packs to 13.9 GB. Almost\nall of it was duplication: \"count-objects -v\" reported 94 million\nin-pack entries, but only 1.46 million remained after a manual\n\"git maintenance run\", which brought the packs down to 0.68 GB (GitHub\nreports about 0.4 GB for the repository). The commit-graph stayed at\nits April state, which made \"git log --topo-order\" over all refs take\nseconds. Two other repositories on the same machine had the same stale\nlock, created on 2026-09-29 and 2026-10-04; both are regular\n(non-partial) clones, so partial clone is not a condition; it likely\nmade the packs pile up faster, since every promisor fetch is kept as a\npack. Other projects report the same symptom, e.g. [3] (auto gc\n\"silently disabled for a week\") and [4].\n\nA note on core.lockfilePid: it cannot simply be used to detect a stale\nmaintenance.lock. With 2.56.0 and core.lockfilePid=true, while the\ndetached child is alive, maintenance~pid.lock contains the pid of the\nparent, which has already exited. A liveness check based on that file\nwould treat a live lock as stale.\n\nSome options, roughly from least to most work (I have not tried to\nimplement any of them):\n\n - When \"maintenance run --auto\" skips because of the lock, leave a\n   trace that a user can find later (for example like the gc.log that\n   a daemonized \"git gc --auto\" leaves), instead of returning silently.\n\n - Record the pid and hostname of the actual holder (the detached\n   child) and ignore the lock when that process is gone on the same\n   host, like lock_repo_for_gc() does for gc.pid.\n\n - Use an OS-level lock that is released when the process dies, as\n   suggested in [1].\n\nThanks,\nmiyaoka\n\n[1]\nhttps://lore.kernel.org/git/CAN477tHJnVnOKfUsG5G9QAVdzYvmUuC8A8Vxt8mtHB23fd=hAQ@mail.gmail.com/\n[2]\nhttps://lore.kernel.org/git/20260511201049.GB22912@coredump.intra.peff.net/\n[3] https://github.com/craigoley/remudero/pull/9555\n[4] https://github.com/solidDoWant/vault-sync/pull/115\n\n"}]}