From: Patrick Steinhardt <ps@pks.im>
To: Farid Zakaria <farid.m.zakaria@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Jeff King <peff@peff.net>, M Hickford <mirth.hickford@gmail.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Jeff Hostetler <jeffhostetler@github.com>
Subject: Re: [PATCH 2/2] credential-cache--daemon: do not take over a running daemon's socket
Date: Tue, 3 Nov 2026 09:01:14 +0100 [thread overview]
Message-ID: <aumUyl6MQa43OFBs@pks.im> (raw)
In-Reply-To: <20261101-fz-credential-cache-race-v1-2-28f0bac51e11@gmail.com>
On Sun, Nov 01, 2026 at 03:29:26PM -0800, Farid Zakaria wrote:
> When no daemon is running, two "git credential-cache store" run at the
> same time each try to start one. unix_stream_listen() removes whatever
> is at the socket path before it binds, so the second daemon takes over
> the socket of the first. The first daemon keeps running, but no client
> can reach it:
>
> - the credential its client stored is lost;
>
> - "git credential-cache exit" does not stop it, and it keeps the
> password in memory until it times out;
>
> - when it does exit, it removes the socket of the daemon that is
> still running, losing that daemon's credentials too.
>
> The fix is to create the socket with unix_ss_create(), which the
> simple-ipc server already uses.
We usually write commit messages as if instructing the code to change.
So: "Fix that by using `unix_ss_create()` instead...".
> diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
> index 0dfa11e2ec..de6720c276 100644
> --- a/builtin/credential-cache--daemon.c
> +++ b/builtin/credential-cache--daemon.c
> @@ -231,12 +232,26 @@ static int serve_cache_loop(int fd)
> static void serve_cache(const char *socket_path, int debug)
> {
> struct unix_stream_listen_opts opts = UNIX_STREAM_LISTEN_OPTS_INIT;
> - int fd;
> + struct unix_ss_socket *server_socket;
> + struct tempfile *socket_file;
> + int ret;
>
> - fd = unix_stream_listen(socket_path, &opts);
> - if (fd < 0)
> + /*
> + * Two clients may each start a daemon at the same time. Bind only
> + * if no other daemon is listening yet; otherwise leave the socket
> + * to that one, and our client will talk to it.
> + */
This explains what you do without giving much context why you do it, so
this comment is somewhat useless. Most importantly...
> + ret = unix_ss_create(socket_path, &opts, -1, &server_socket);
> + if (ret == -2) {
> + printf("ok\n");
> + return;
... you mention that you write "ok" in your commit message, but you
don't explain why that's the right thing to do. So why should the daemon
pretend that everything was alright in the case where it fails to start?
> + }
> + if (ret < 0)
> die_errno("unable to bind to '%s'", socket_path);
>
> + /* Remove the socket at exit only now that it is ours. */
> + socket_file = register_tempfile(socket_path);
This comment doesn't really add much value, if you ask me.
Patrick
next prev parent reply other threads:[~2026-11-03 8:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 23:29 [PATCH 0/2] credential-cache: fix two races when daemons start at once Farid Zakaria
2026-11-01 23:29 ` [PATCH 1/2] credential-cache--daemon: allow a concurrently created socket dir Farid Zakaria
2026-11-03 8:01 ` Patrick Steinhardt
2026-11-01 23:29 ` [PATCH 2/2] credential-cache--daemon: do not take over a running daemon's socket Farid Zakaria
2026-11-03 8:01 ` Patrick Steinhardt [this message]
2026-11-03 17:24 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aumUyl6MQa43OFBs@pks.im \
--to=ps@pks.im \
--cc=Johannes.Schindelin@gmx.de \
--cc=farid.m.zakaria@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jeffhostetler@github.com \
--cc=mirth.hickford@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox