From: Junio C Hamano <gitster@pobox.com>
To: Farid Zakaria <farid.m.zakaria@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
Patrick Steinhardt <ps@pks.im>,
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, 03 Nov 2026 09:24:13 -0800 [thread overview]
Message-ID: <xmqqik2dakw2.fsf@gitster.g> (raw)
In-Reply-To: <20261101-fz-credential-cache-race-v1-2-28f0bac51e11@gmail.com> (Farid Zakaria's message of "Sun, 01 Nov 2026 15:29:26 -0800")
Farid Zakaria <farid.m.zakaria@gmail.com> writes:
> + /* Remove the socket at exit only now that it is ours. */
> + socket_file = register_tempfile(socket_path);
> +
> printf("ok\n");
> fclose(stdout);
> if (!debug) {
> @@ -244,10 +259,11 @@ static void serve_cache(const char *socket_path, int debug)
> die_errno("unable to point stderr to /dev/null");
> }
>
> - while (serve_cache_loop(fd))
> + while (serve_cache_loop(server_socket->fd_socket))
> ; /* nothing */
>
> - close(fd);
> + delete_tempfile(&socket_file);
> + unix_ss_free(server_socket);
> }
Is it sane to mix unix_ss_* API with tempfile like this? For Unix
domain sockets managed by the unix_ss_* API, isn't
register_tempfile() unnecessary and architecturally undesirable?
If the daemon exits abruptly without cleaning up its socket, it is
entirely harmless. The next time a daemon starts, unix_ss_create()
will find that the socket is stale (is_another_server_alive() will
return 0), and it will safely unlink() the stale socket before
binding.
E.g., fsmonitor--daemon.c calls ipc_server_init_async(), which is
implemented in ipc-unix-socket.c by calling setup_listener_socket(),
which in turn calls create_listener_socket(), which in turn finally
calls unix-stream-server.c:unix_ss_create(). In that function, we
check if somebody else is listening or if the on-filesystem socket
is stale, unlink and rebind by calling unix_stream_listen(), and
continue.
By invoking register_tempfile(), the Unix socket would be managed
by the tempfile API. At normal exit, delete_tempfile(&socket_file)
blindly unlinks the socket file. If the daemon is killed abruptly by
a signal (e.g., SIGTERM), the tempfile API's signal handler will
similarly unlink the socket blindly. Doesn't this completely bypass
the safety built into unix_ss_free(), though? The API deliberately
calls unix_ss_was_stolen() (which checks the inode) to prevent a
dying daemon from unlinking a socket that has since been taken over
by a new daemon, but delete_tempfile() has no way of knowing that.
It runs first (or runs in the signal handler) and blindly unlinks
the socket, defeating the safety check, no?
next prev parent reply other threads:[~2026-11-03 17:24 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
2026-11-03 17:24 ` Junio C Hamano [this message]
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=xmqqik2dakw2.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=farid.m.zakaria@gmail.com \
--cc=git@vger.kernel.org \
--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.