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

Re: Git push race condition?

From
Jeff King <peff@peff.net>
Date
Mar 24, 2014, 22:51 UTC
Message-ID
<20140324225136.GA17080@sigill.intra.peff.net>
In-Reply-To
<CACBZZX4ZEPA3sBp4-3QF6de0EWXzPkcOiqSxH3_CXV27Z=gxtw@mail.gmail.com>
On Mon, Mar 24, 2014 at 10:16:52PM +0100, Ævar Arnfjörð Bjarmason wrote:
Show 11 quoted lines
> > error: Ref refs/heads/master is at
> > 4584c1f34e07cea2df6abc8e0d407fe016017130 but expected
> > 61b79b6d35b066d054fb3deab550f1c51598cf5f
> > remote: error: failed to lock refs/heads/master
> 
> I also see this error once in a while. I read the code a while back
> and it's basically because there's two levels of locks that
> receive-pack tries to get, and it's possible for two pushers to get
> the first lock due to a race condition.
> 
> I've never seen data loss due to this though, because the inner lock is atomic.

The reason is that there are not 2 locks. Each side remembers the "old" value when it started the operation, and only takes a lock when it comes time to write the ref (and then checks that the old value is still current). Two pushes happening simultaneously do not have any idea that the other is occurring.

-Peff
Previous: Scott SandlerNext: Jeff King
Message 8 of 17 in “Git push race condition?”
  1. Scott SandlerMar 24, 2014
  2. Matthieu MoyMar 24, 2014
  3. Scott SandlerMar 24, 2014
  4. Matthieu MoyMar 24, 2014
  5. Junio C HamanoMar 24, 2014
  6. Ævar Arnfjörð BjarmasonMar 24, 2014
  7. Scott SandlerMar 24, 2014
  8. Jeff KingMar 24, 2014
  9. Jeff KingMar 24, 2014
  10. Nasser GrainawiMar 24, 2014
  11. Scott SandlerMar 25, 2014
  12. Matthieu MoyMar 25, 2014
  13. Scott SandlerMar 25, 2014
  14. Matthieu MoyMar 25, 2014
  15. Jeff KingMar 25, 2014
  16. Scott SandlerApr 10, 2014
  17. Matthieu MoyApr 11, 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.