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

Re: [PATCH 1/2] credential-cache--daemon: allow a concurrently created socket dir

From
Jeff King <peff@peff.net>
Date
Nov 4, 2026, 02:58 UTC
Message-ID
<20261104025835.GB1492379@coredump.intra.peff.net>
In-Reply-To
<20261101-fz-credential-cache-race-v1-1-28f0bac51e11@gmail.com>
On Sun, Nov 01, 2026 at 03:29:25PM -0800, Farid Zakaria wrote:
Show 10 quoted lines
> When no daemon is running, two "git credential-cache store" run at the
> same time each try to start one. If the socket directory does not exist
> yet, both daemons try to create it. The one that comes second dies:
> 
>     fatal: unable to mkdir '<home>/.cache/git/credential': File exists
> 
> That client then fails with "cache daemon did not start".
> 
> The fix is to ignore EEXIST from mkdir(), and check the directory's
> permissions the same way as for one that already existed.

Makes sense. This is what safe_create_leading_directories() does for all of the other path components. So of course I wondered why we bothered to do this last one ourselves, but the comment (which is just out of the context of your patch) explains it:

                /*
                 * We must be sure to create the directory with the correct mode,
                 * not just chmod it after the fact; otherwise, there is a race
                 * condition in which somebody can chdir to it, sleep, then try to open
                 * our protected socket.
                 */

If we find the directory already created, then we are subject to the same race, but it is reasonable to assume that whoever created it did so in the correct non-racy way.

-Peff
Previous: Farid ZakariaNext: Farid Zakaria
Message 5 of 14 in “credential-cache: fix two races when daemons start at once”
  1. 0/2 credential-cache: fix two races when daemons start at onceFarid Zakaria, Nov 1, 2026
  2. 1/2 credential-cache--daemon: allow a concurrently created socket dirFarid Zakaria, Nov 1, 2026
  3. Patrick SteinhardtNov 3, 2026
  4. Farid ZakariaNov 4, 2026
  5. Jeff KingNov 4, 2026
  6. 2/2 credential-cache--daemon: do not take over a running daemon's socketFarid Zakaria, Nov 1, 2026
  7. Patrick SteinhardtNov 3, 2026
  8. Farid ZakariaNov 4, 2026
  9. Junio C HamanoNov 3, 2026
  10. Jeff KingNov 4, 2026
  11. 0/3 credential-cache: fix two races when daemons start at onceFarid Zakaria, Nov 4, 2026
  12. 1/3 credential-cache--daemon: do not apply core.sharedRepositoryFarid Zakaria, Nov 4, 2026
  13. 2/3 credential-cache--daemon: allow a concurrently created socket dirFarid Zakaria, Nov 4, 2026
  14. 3/3 credential-cache--daemon: do not take over a running daemon's socketFarid Zakaria, Nov 4, 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.