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

Re: [PATCH 2/2] commit: lock index before reading

From
JWJun Wu <quark.zju@gmail.com>
Date
Oct 15, 2026, 00:19 UTC
Message-ID
<20261015001938.2092523-1-quark.zju@gmail.com>
In-Reply-To
<20261014100432.GB1344504@coredump.intra.peff.net>
Hi Peff,
On Wed, 14 Oct 2026 06:04:32 -0400, Jeff King wrote:
> I do think your patch fixes the problem. But we probably want to discuss
> that in the commit message as a motivation (and likewise, discuss the
> fact that we may be holding the lock for longer).

Will do in v2: describe the race as motivation, and mention the longer hold trade-off.

I'd like to note 'commit' is just one command with the read/lock order issue. There are many others, like: reset, rebase, stash, am, merge, etc. Some are easy to fix, some seem tricky (e.g. merge).

Do you think that I should fix all order issues before adding the timeout?

Note Patch 1 alone does not hurt - if a command has the read/lock order issue and is therefore racy, then the timeout feature is automatically disabled (by the 'initialized' check) so the racy command behaves exactly the same as before, not worse.

My plan is to add the timeout support first, then incrementally fix order issues, starting from the easy/more common ones (e.g. commit).

> There's probably some kind of hybrid world where we optimistically read
> without the lock, then take the lock, and then check (cheaply-ish) that
> the index didn't change since what we read. But I don't think we do that
> in this code path.

For reference, 'status' is such an example, although its write is optional. 'add -i' could be another example - it avoids locking when waiting for user input, although it lacks the "didn't change" check right now.

-Jun
Previous: Jeff KingNext: Junio C Hamano
Message 11 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.