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

Re: Race condition with git-status and git-rebase

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 8, 2014, 22:56 UTC
Message-ID
<xmqq1tx72zxo.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20140408184421.GD5208@abyss.hitronhub.home>
Yiannis Marangos <yiannis.marangos@gmail.com> writes:
Show 8 quoted lines
> process A calls git-rebase
> process A applies the 1st commit
> process B calls git-status
> process B calls read_cache()
> process A applies the 2nd commit
> process B holds the index.lock
> process B writes back the old index (the one that was read from read_cache())
> process A applies the 3rd commit (now the 3rd commit contains also a revert of the 2nd)

The above sequence shows we are clearly doing it wrong. B's taking of the lock is not protecting anything from anybody.

We try minimizing the lock contention by delaying the taking of the lock by B, but even if we leave it at the current location in the above sequence, at least B must verify that the contents of the index it just took the lock on still matches what it read with its earlier call to read_cache(), which would make it pretend as if it took the lock before it did read_cache(), before writing the refreshed results back.

I think we have a checksum for the entire index file at the end, so one fix might be to teach read_index_from() to read that and store it in a new field in "struct index_state", and then make the "opportunistic update" codepath to verify that the index on the filesystem still has the same checksum.

Previous: Yiannis Marangos
Message 3 of 3 in “Race condition with git-status and git-rebase”
  1. Yiannis MarangosApr 8, 2014
  2. Yiannis MarangosApr 8, 2014
  3. Junio C HamanoApr 8, 2014

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.