All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Farid Zakaria" <farid.m.zakaria@gmail.com>
To: "Patrick Steinhardt" <ps@pks.im>,
	"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: Wed, 04 Nov 2026 10:28:03 -0800	[thread overview]
Message-ID: <DMMN0K2447KN.36D8GZ1EWAVP0@gmail.com> (raw)
In-Reply-To: <aumUyl6MQa43OFBs@pks.im>

On Tue Nov 3, 2026 at 12:01 AM PST, Patrick Steinhardt wrote:
> 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...".
>

When I sent V2 I will fix this.

>> 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?
>

The client in builtin/credential-cache.c:spawn_daemon() reads the
daemon's stdout and dies with "cache daemon did not start" unless it
gets "ok"

"ok" is part of the protocol between the client and the daemon. The
client expects to see "ok" and then it connects to the socket.

I can put this reasoning as a comment in the code. 
Following Peff's suggestion, I'll also exit(0) there
to make clear that this process is done.

>> +	}
>> +	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



  reply	other threads:[~2026-11-04 18:28 UTC|newest]

Thread overview: 14+ 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-04 18:25     ` Farid Zakaria
2026-11-04  2:58   ` Jeff King
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
2026-11-04 18:28     ` Farid Zakaria [this message]
2026-11-03 17:24   ` Junio C Hamano
2026-11-04  3:07   ` Jeff King
2026-11-04 19:53 ` [PATCH v2 0/3] credential-cache: fix two races when daemons start at once Farid Zakaria
2026-11-04 19:53   ` [PATCH v2 1/3] credential-cache--daemon: do not apply core.sharedRepository Farid Zakaria
2026-11-04 19:53   ` [PATCH v2 2/3] credential-cache--daemon: allow a concurrently created socket dir Farid Zakaria
2026-11-04 19:53   ` [PATCH v2 3/3] credential-cache--daemon: do not take over a running daemon's socket Farid Zakaria

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=DMMN0K2447KN.36D8GZ1EWAVP0@gmail.com \
    --to=farid.m.zakaria@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jeffhostetler@github.com \
    --cc=mirth.hickford@gmail.com \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.