Article View: linux.kernel.git
Article #2356Re: [PATCH 2/2] credential-cache--daemon: do not take over a running daemon's socket
From: "Farid Zakaria"
Date: Wed, 04 Nov 2026 18:28
Date: Wed, 04 Nov 2026 18:28
82 lines
13952 bytes
13952 bytes
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
Technical Details
Message-ID:
<DMMN0K2447KN.36D8GZ1EWAVP0@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74473-linux-kernel-git=dewy.ruReferences:
<20261101-fz-credential-cache-race-v1-0-28f0bac51e11@gmail.com> <20261101-fz-credential-cache-race-v1-2-28f0bac51e11@gmail.com> <aumUyl6MQa43OFBs@pks.im>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74473-linux-kernel-git=dewy.ru
From: farid.m.zakaria@gmail.com ("Farid Zakaria")
Newsgroups: linux.kernel.git
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
Organization: Usenet Network
Message-ID: <DMMN0K2447KN.36D8GZ1EWAVP0@gmail.com>
References: <20261101-fz-credential-cache-race-v1-0-28f0bac51e11@gmail.com>
<20261101-fz-credential-cache-race-v1-2-28f0bac51e11@gmail.com>
<aumUyl6MQa43OFBs@pks.im>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="3463036"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:YXBnnHV3UgN89tOXUjiFVliOgaA= sha256:vSceQqbT+aLLlghFsWHS/HJCZoyp4hmQ9n/BUrnuQ60=
sha1:DXHkW020vWGm1QmV4zzF3W1zsUU= sha256:M/kZEHkYbDScgT5CmgnzwfqtdTlZPySvG03pnNtU/10=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 68275112CFC; Wed, 4 Nov 2026 22:10:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id j70ANweZJx1Q;
Wed, 4 Nov 2026 22:10:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-74473-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 4D7CB1122CF; Wed, 4 Nov 2026 22:10:17 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 2F0EEC03F3; Wed, 4 Nov 2026 18:29:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793816888;
b=SVhayA8Fi76DXJAcUi7ics5nzfdAci/zcwb/F+JZSjQFvH3SghOAUrAo2gDrmFq64n1B
bS1lBGOAAgZ8lwrNQk6+lcB+iLsTuCR4YCMkNwLeS0qgqefccyEjo0QjZXJEFLTL8hPHm
54X6+Qvan5m3FuI4KU2unmECnqHW13DeYn2CxHr/XbcZYse7/CxFmrZzLO8tQOHLi54EQ
BEE1DlqOxy3zIGf8lwGA1djwoKK2yDlJm2SYJL0NF8z6mYvJHrbn2euBn4axjvc1SrzwF
31ThZOJwr342EL8/oKoXQrpshSye61qNGmZdYnEVx5mEOBOuN6Omo+0NL+yq8BxrBnQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793816888;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:Mime-Version:
Content-Transfer-Encoding:Content-Type:Date:Message-Id:Cc:Subject:
From:To:X-Mailer:References:In-Reply-To;
bh=CJV5CRWYtpeS+0igPrweO+tsB4keYysWAqLhR868Lkg=;
b=R+7Rm1gW9XCTlBWfEe+PJVIEKOSVG8JximegCB7dkkTQIkDQha4WyR+1jpZ4h1XwZ+c4
GXa6YVa+MahJwHHuS4LWupY1hKpI6Jb4wIqL4pAJmT6p21F+zxsiEwrSuxJcZfw3TapP3
LMLqcLLVuW0kUJkKhF1SewSl2Y3HoYZACYaKUuv1uxPZRhAtfXLW+/EUokECa/ky3z5u/
5NnNOFo+LCTLI3h546/y72/Ooq7PIhKT6bMcdYgoE5QsdU/9AD17K4+EGlrW26IrKZY+h
b7SFi37FsCboAVLGElBuqWAFPHDj4izMmJQo0Z7/+kChvRiSxGdiJliwT0p9mEPGEvg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=B3+75E6W;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 477D9606C44E;
Wed, 4 Nov 2026 18:28:08 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=B3+75E6W
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.45
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793816887;
b=I8Vp5PUZlK1ew3zUUi1wtoVmwR/ZBtwnrd/xbAXwDhmiEJ5rppeTQebmxeQCkUcNIlgW
Hh3ChSPZKxNn2u6EnIzEfVPdAZc43uU+Fk5hL7uCIBfunVIPH0JKU3V3LZKCT4LzGb0Ku
KY9NvSIpvfB0I/iO13fvmyTaZLHKHnUZdBwoGD3FSCOA6mbyelRLG3EzRJyIeb6Ymv7zx
cpspirWfOakC3p+F6kVyRbmpaKCElaoX5T+k+YuuFK5h1hv3UqRgzsVS9K1JIzioieT9p
9MNZymErq/46tnKYiia0cWUrnPunVDut1yDKUE9Bz3su5R3ieSpUgnQJ/s3hbvn5rfA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793816887;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Mime-Version:
Content-Transfer-Encoding:Content-Type:Date:Message-Id:Cc:Subject:
From:To:X-Mailer:References:In-Reply-To;
bh=CJV5CRWYtpeS+0igPrweO+tsB4keYysWAqLhR868Lkg=;
b=RPSNI089/OhCbQMjnu1StHuajlFs9qfcwS57cCdCl5fiRuoBnzkF/v1kctYZbTbH1xiS
niieu4wbP89iBPYaTPjQwtyvdnu4uxbNh996iWzQ12aMBAxRtRdm2cSJr+wSdksiAzEul
ceuqO63HdqnoruOB8JoDiDtFs7MGiOBnW7C3oHex5kb2eAbAsdpXnRjpQkuj9b/xDoOGm
sEmMF2uvuz70aEio9juZQcaAMQt3XsWzcqffb5cefWSutKz+rvq724HibdgQwBWpDkRMt
VfMrfxV6+Kk8+bjOxuccFNEwkF0ON30wWIBCCoa5Kz092HgXTDrKIgHZ4HxkjEcRwQw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=B3+75E6W;
arc=none smtp.remote-ip=209.85.216.45
X-Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 169B3606A339
for <git@vger.kernel.org>; Wed, 4 Nov 2026 18:28:07 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 169B3606A339
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-3b09a83d12aso522464a91.2
for <git@vger.kernel.org>; Wed, 04 Nov 2026 10:28:07 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793816886; x=1794421686; darn=vger.kernel.org;
h=in-reply-to:references:to:from:subject:cc:message-id:date
:content-type:content-transfer-encoding:mime-version:from:to:cc
:subject:date:message-id:reply-to:content-type;
bh=CJV5CRWYtpeS+0igPrweO+tsB4keYysWAqLhR868Lkg=;
b=B3+75E6W8FuQUn5c5ELPzq/8ryZPA+dpJEzueRY/zLWwR7CHgDdYPgPRIvzWE2gNqm
WjFkHs0N7SWaoMspcv/fc8TFl+rrbimTKXM788UmvoDMWXF1v0JpFCk6y2ItIWDYD3xU
P6Id03LYfk3kEyhptZRbdcFMlQV43YH+xeMvACypjt2HfWnjWNF6UsZvg+wp61Z/va41
CM0MFgAsY58hEJpA9hGSQEWKoTufeoVmpJpPo4PY8nYHG/Au550oqLhJIlfzEszsT/dj
Wq5NnTyXHar/1+eIex7O7ZXtpUFRIbv5/J/sNC3SY3STTfqpd/cPO0DJFn9q3yw9Bo73
djuQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793816886; x=1794421686;
h=in-reply-to:references:to:from:subject:cc:message-id:date
:content-type:content-transfer-encoding:mime-version:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=CJV5CRWYtpeS+0igPrweO+tsB4keYysWAqLhR868Lkg=;
b=nwuTzIs/Gn7AdPl1fKphgdSPwWtlQDnbNijbINs0Tk3Mo19R0W01gW5p1wWE+v83Tw
MigKc5mfiIkmy7hzYFOBMO1I9n57Of0aLxA9uSyGUj2XYI+l1HFxm+foo/kCDSjo8xxB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b5mr2268245a91.49.1793816886402;
Wed, 04 Nov 2026 10:28:06 -0800 (PST)
X-Received: from localhost ([73.222.46.22])
by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0b3265a52sm96117a91.10.2026.11.04.10.28.04
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Wed, 04 Nov 2026 10:28:05 -0800 (PST)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-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>
X-Mailer: aerc 0.22.0
X-In-Reply-To: <aumUyl6MQa43OFBs@pks.im>