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

Race condition in git push --mirror can cause silent ref rewinding

From
Alex Vandiver <alex@chmrr.net>
Date
Jul 2, 2014, 21:10 UTC
Message-ID
<53B47535.3020101@chmrr.net>
Heya,

We recently ran into a particularly troubling race condition, discovered in git 2.0.0. The setup for it is as follows:

The repository is a bare repository, which developers push to via ssh; it mirrors its changes out onto github. In its config:

    [remote "github"]
        url = git@github.com:bestpractical/rt.git
        fetch = +refs/*:refs/*
        mirror = yes
It has a post-receive hook which does:
    sudo -u git -H /usr/bin/git push github

We recently saw a situation where a push of a new branch caused a simultaneous update of a different branch (by a different user) to be rewound. From the reflog of the created branch (4.2/html-gumbo-loading):

    0000000000000000000000000000000000000000
1aefd600fcbb5ded14376f77d77a14758668fb39 Wallace Reis
<wreis@bestpractical.com> 1404326443 -0400       push
And the updated branch (4.2-trunk), which was rewound:
    44dc8ad0e4603e3f674b7c00deacc122ca52707a
1e743b6225d502ad1a265929fb873f4c0bf4f8a5 Kevin Falcone
<falcone@bestpractical.com> 1404326446 -0400    push
    1e743b6225d502ad1a265929fb873f4c0bf4f8a5
44dc8ad0e4603e3f674b7c00deacc122ca52707a git <git@bestpractical.com>
1404326446 -0400        update by push

It is my belief that this comes because the "--mirror" argument causes the local refs to be treated as tracking refs -- and thus updates all of them during the push. I believe the race condition is thus:

  1. User A starts a push --mirror; git records the values of the refs
  2. User B updates a ref, commit mail goes out, etc
  3. User A's push completes, updates "tracking" branch to value at (1).

Needless to say, silently losing commits which appeared for all purposes to be pushed successfully (neither User A nor User B sees anything out of the ordinary) is extremely troubling.

 - Alex
Next: Junio C Hamano
Message 1 of 4 in “Race condition in git push --mirror can cause silent ref rewinding”
  1. Alex VandiverJul 2, 2014
  2. Junio C HamanoJul 2, 2014
  3. Alex VandiverJul 2, 2014
  4. Alex VandiverJul 14, 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.