git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: HEAD.lock and git maintenance

From
Patrick Steinhardt <ps@pks.im>
Date
May 28, 2025, 06:51 UTC
Message-ID
<aDayWsRRA3ur-Pwi@pks.im>
In-Reply-To
<CAJoAoZ=OGOWVWQJNSk0YAVA0V_O68Y4ycXdw6d8bJ0=OhnNGeQ@mail.gmail.com>
On Tue, May 27, 2025 at 09:33:50AM -0700, Emily Shaffer wrote:
> On Mon, May 26, 2025 at 6:22 AM Patrick Steinhardt <ps@pks.im> wrote:
[snip]
Show 16 quoted lines
> > > Using GIT_TRACE_PERFORMANCE, we noticed that a Git maintenance process
> > > (/usr/libexec/git-core/git maintenance run --auto --no-quiet --detach)
> > > sometimes starts after the git fetch command, occasionally in detached
> > > mode. We suspect this operation is causing the issue because we've
> > > verified that the git maintenance command requires HEAD.lock before it
> > > starts running. We are considering setting maintenance.autoDetach to
> > > false. We are unsure if this is a bug or if it is working as intended,
> > > and would appreciate your comments on this.
> >
> > thanks for your report! A couple months ago there was a similar
> > discussion with someone else, but I cannot find that thread anymore,
> > unfortunately.
> 
> Google had a big problem with this behavior about a year ago, I'm not
> sure if we got far with a thread about it though. That may be what
> you're thinking of.

Yeah, I remembered it was Google that had problems, but I thought that this was at max half a year ago. So I didn't care to look back further than that :)

Show 19 quoted lines
> > The root cause here is repository maintenance with `--auto --detach`
> > will detach before spawning git-gc(1). This command may decide to pack
> > your references and thus cause them to be locked. This then triggers a
> > race condition, where the next Git command that wants to modify refs may
> > not be able to lock "packed-refs" because we are still busy repacking
> > them.
> >
> > The actual timeout to lock the "packed-refs" file is configurable via
> > "core.packedRefsTimeout", so bumping this value may make the problem
> > less likely to happen. But it's only papering over the actual issue.
> >
> > I'll send a patch series soonish that fixes this issue. I think the
> > solution would be to make git-maintenance(1) learn about tasks that
> > should run previous and after daemonizing the process to avoid this race
> > condition. The effect would be that the caller of auto-maintenance will
> > not continue before refs have been packed, which is similar to what
> > git-gc(1) used to do in the past.
> 
> We'll look forward to this series with interest, thanks.

For reference, I've sent the series yesterday via [1]. I'll keep you Cc'd on that series from now on.

Patrick
[1]: <20250527-b4-pks-maintenance-ref-lock-race-v1-0-e1ceb2dea66e@pks.im>
Previous: Emily Shaffer
Message 4 of 4 in “HEAD.lock and git maintenance”
  1. david asrafMay 22, 2025
  2. Patrick SteinhardtMay 26, 2025
  3. Emily ShafferMay 27, 2025
  4. Patrick SteinhardtMay 28, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.