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

Re: [PATCH 1/2] repository: add core.indexLockTimeout

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Oct 13, 2026, 21:40 UTC
Message-ID
<CALnO6CD8c+nZktineZjo6PkZbXXEQfKto-cvJvLW=_xjTPVCRA@mail.gmail.com>
In-Reply-To
<20261013172315.2997446-2-quark.zju@gmail.com>
Hi Jun,
On Tue, Oct 13, 2026 at 5:07 PM Jun Wu <quark.zju@gmail.com> wrote:
Show 11 quoted lines
>
> From: Jun Wu <quark@meta.com>
>
> When an IDE runs `git status` periodically in the background, `status`
> can take the index lock, and this prevents other commands like `add`,
> `commit` from running.
>
> Commit 27344d6a6c (git: add --no-optional-locks option, 2017-09-27)
> avoids the conflict by letting background `git --no-optional-locks status`
> skip the index lock, at the cost of losing refreshed stat info, so
> the next `status` has to re-hash files.

Interesting. That must be the slow down you mentioned in your cover letter? I'm trying to make sense of this. I think you're saying that not having the index lock means status would "lose" refreshed info: we're not throwing away the *existing* stat info, just the ones we recomputed for this "git --no-optional-locks status" invocation, right?

I suppose I don't see how that causes things to slow down continually, but I bet I'm missing something :)

Show 13 quoted lines
> Approach the conflict from the other side: let non-status commands wait
> for the index lock. Mercurial and Sapling have a similar "waiting for wlock"
> behavior, and Git already has `core.{config,filesRef}LockTimeout`.
>
> Ideally all non-status commands can wait for the index lock. However,
> some code paths (e.g. `commit`) load the index without locking, then lock and
> write changes. It is already racy and the wait behavior would make it much
> worse. As a defense, waiting is disabled if index was already read.
>
> Default timeout is 1s, effective but not too long to avoid breaking potential
> user expectation (e.g. "an index.lock error means I should check whether a
> commit message editor is open somewhere"). Tests that are slowed down by the
> default timeout now set the timeout to 0.

It feels weird to me to fix mostly-invisible behavior from external tools with a config option, though. I think of config *mostly* as user-facing (whether that user is a client of the Git CLI or configuring a server repo), and I don't see how we could teach users to look for this or know what a reasonable setting should be for themselves :/ Further, we already have a lot of config options! (I'm guilty of adding one recently, heh.) It can definitely be overwhelming for users to think about all the options, and I suspect many just don't as a result.

I applaud the effort for sensible defaults here, which I think will help.

Anyway, maybe it's just me: if others are happy with this approach, great. I think I would prefer to see us try to address the underlying performance problems, though, if we can. (Maybe we can have some way for git-status to not throw away all its work, or some other good way to communicate to IDEs that want to poll?)

Previous: Jun WuNext: Jun Wu
Message 3 of 20 in “Add a way to wait for index lock”
  1. 0/2 Add a way to wait for index lockJun Wu, Oct 13, 2026
  2. 1/2 repository: add core.indexLockTimeoutJun Wu, Oct 13, 2026
  3. D. Ben KnobleOct 13, 2026
  4. Jun WuOct 14, 2026
  5. D. Ben KnobleOct 14, 2026
  6. Junio C HamanoOct 13, 2026
  7. Jun WuOct 14, 2026
  8. Ben KnobleOct 19, 2026
  9. 2/2 commit: lock index before readingJun Wu, Oct 13, 2026
  10. Jeff KingOct 14, 2026
  11. Jun WuOct 15, 2026
  12. Junio C HamanoOct 13, 2026
  13. Jun WuOct 14, 2026
  14. Jeff KingOct 14, 2026
  15. 0/4 Wait for the index lock instead of failingJun Wu, Oct 17, 2026
  16. 1/4 repository: add repo_try_hold_locked_index()Jun Wu, Oct 17, 2026
  17. 2/4 repository: add core.indexLockTimeoutJun Wu, Oct 17, 2026
  18. 3/4 commit: fix write raceJun Wu, Oct 17, 2026
  19. 4/4 reset: fix write raceJun Wu, Oct 17, 2026
  20. Mihai CosmaOct 22, 2026

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.