From: Junio C Hamano <gitster@pobox.com>
To: Joerg Thalheim <joerg@thalheim.io>
Cc: git@vger.kernel.org, Patrick Steinhardt <ps@pks.im>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH v2] config: retry acquiring config.lock, configurable via core.configLockTimeout
Date: Thu, 23 Jul 2026 12:54:00 -0700 [thread overview]
Message-ID: <xmqq33x9h487.fsf@gitster.g> (raw)
In-Reply-To: <20260517132111.1014901-1-joerg@thalheim.io> (Joerg Thalheim's message of "Sun, 17 May 2026 15:21:11 +0200")
Joerg Thalheim <joerg@thalheim.io> writes:
> From: Jörg Thalheim <joerg@thalheim.io>
>
> Concurrent config writers race for the ".lock" file, which is taken
> with open(O_EXCL) and no retry, so the losers fail right away with
> "could not lock config file".
>
> This shows up with parallel "git worktree add -b" against the same
> repository: each one writes a couple of branch.* keys and the losers
> fail at random. Worse, "git worktree add" doesn't propagate that
> failure to its exit code, so the tracking config is silently dropped.
> (The swallowed error is a separate bug.)
>
> Retry instead of giving up on the first EEXIST. The lock is only held
> while rewriting a small file, so the loser only has to wait out the
> other writers. Same approach as 4ff0f01cb7 (refs: retry acquiring
> reference locks for 100ms, 2017-08-21).
>
> On the semantics: the on-disk config is read only after the lock is
> taken, so writers touching different keys can't lose each other's
> change. Writers touching the same key still get last-writer-wins, but
> that is already the case today and would need a compare-and-swap config
> API to fix. The retry only turns hard failures into successes.
>
> Default to 1000ms, like core.packedRefsTimeout: same shape of problem,
> one shared file everyone serializes through. A larger timeout only
> costs anything when a stale lock is left behind by a crash, which is
> rare; a smaller one fails spuriously on slow filesystems (NTFS has
> been seen needing more than 100ms). Make it configurable as
> core.configLockTimeout. There is no chicken-and-egg problem: we read
> the config before we lock it.
>
> microsoft/git carries a similar patch (core.configWriteLockTimeoutMS,
> default off) for Scalar's tests. Defaulting to non-zero here because
> the worktree case fails silently.
>
> Helped-by: Patrick Steinhardt <ps@pks.im>
> Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
> ---
> Thanks for the review and for poking me, this had fallen off my radar.
>
> v1 -> v2:
>
> - added core.configLockTimeout. Johannes is right that there is no
> chicken-and-egg problem (config is read before the lock), so no env
> var needed.
> - default bumped to 1000ms; packed-refs is the closer precedent and it
> keeps NTFS out of trouble.
> - commit message now covers the read-after-lock / last-writer-wins
> semantics Patrick asked about.
> - added tests; existing stale-lock tests in t3200/t5505 now pass
> -c core.configLockTimeout=0 so they still fail fast.
>
> I matched the core.filesRefLockTimeout naming rather than reusing
> microsoft/git's core.configWriteLockTimeoutMS, but can switch if the
> downstream compat matters more.
I was reviewing the whats-cooking and noticed there are a handful of
stalled topics that are not going anywhere, and this is one of them.
This time it had fallen off my radar, sorry about that. All the
outstanding issues seem to have been resolved, so let's merge it
down to 'next'.
Thanks.
prev parent reply other threads:[~2026-07-23 19:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 10:01 [PATCH] config: retry acquiring config.lock for 100ms Joerg Thalheim
2026-04-03 17:53 ` Junio C Hamano
2026-04-08 10:34 ` Patrick Steinhardt
2026-05-11 2:32 ` Junio C Hamano
2026-05-11 7:33 ` Patrick Steinhardt
2026-05-11 9:06 ` Jörg Thalheim
2026-05-11 10:01 ` Patrick Steinhardt
2026-05-17 11:27 ` Johannes Schindelin
2026-05-17 13:21 ` [PATCH v2] config: retry acquiring config.lock, configurable via core.configLockTimeout Joerg Thalheim
2026-05-18 0:46 ` Junio C Hamano
2026-05-18 8:07 ` Patrick Steinhardt
2026-07-08 7:32 ` Johannes Schindelin
2026-07-08 14:49 ` Junio C Hamano
2026-05-28 11:51 ` Johannes Schindelin
2026-05-28 12:23 ` Junio C Hamano
2026-07-07 11:39 ` Johannes Schindelin
2026-07-07 18:16 ` Junio C Hamano
2026-07-23 19:54 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq33x9h487.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=joerg@thalheim.io \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox