From: Patrick Steinhardt <ps@pks.im>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] receive-pack: fix stale packfile locks when dying
Date: Fri, 10 Mar 2023 07:24:36 +0100 [thread overview]
Message-ID: <ZArNJHMmPd8QCLwQ@ncase> (raw)
In-Reply-To: <ZAoCUPsHbstSJ0+B@coredump.intra.peff.net>
[-- Attachment #1: Type: text/plain, Size: 2695 bytes --]
On Thu, Mar 09, 2023 at 10:59:12AM -0500, Jeff King wrote:
> On Thu, Mar 09, 2023 at 02:09:23PM +0100, Patrick Steinhardt wrote:
>
> > Now in production systems we have observed that those `.keep` files are
> > sometimes not getting deleted as expected, where the result is that
> > repositories tend to grow packfiles that are never deleted over time.
> > This seems to be caused by a race when git-receive-pack(1) is killed
> > after we have migrated the kept packfile from the quarantine directory
> > into the main object database. While this race window is typically small
> > it can be extended for example by installing a `proc-receive` hook.
>
> That makes sense, and I think this is a good direction.
>
> > Fix this race by installing an atexit(3P) handler that unlinks the keep
> > file.
>
> This will work if we call die(), but I think you'd be better off using
> the tempfile subsystem:
>
> - this patch doesn't handle signal death, and I don't see any reason
> you wouldn't want to handle it there (in fact, from your
> description, it sounds like signal death is the culprit you suspect)
>
> - this will double-unlink in most cases; once when we intend to after
> calling execute_commands(), and then it will try again (and
> presumably fail) at exit. Probably not a huge deal, but kind of
> ugly. You could set it to NULL after unlinking, but...
>
> - as the variable is not marked as volatile, a signal that causes an
> exit could cause the handler to see an inconsistent state if you
> modify it after setting up the handler. The tempfile code gets this
> right and is pretty battle-tested.
Ah, I didn't know that you can easily register an already-existing file
as tempfile. That is indeed much nicer, thanks!
> I think one could also make an argument that index_pack_lockfile()
> should return a tempfile struct itself, but I didn't look too closely at
> the other caller on the fetch side (but it should be conceptually the
> same).
I had a look at it, but git-fetch-pack(1) works quite differently in
that regard as it also supports the case where the packfile lock should
stay locked after it exits via the `--keep` switch. So the logic is more
intricate here.
Furthermore, git-fetch-pack(1) only does the locking, but never unlocks
the packfiles. That is instead handled by git-fetch(1). So converting
the interface to use tempfiles directly wouldn't work as we are crossing
process boundaries here.
And last but not least, git-fetch(1) already knows to unlock packs both
via an atexit handler and via a signal handler. So there is nothing to
be done here.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-03-10 6:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 13:09 [PATCH] receive-pack: fix stale packfile locks when dying Patrick Steinhardt
2023-03-09 15:59 ` Jeff King
2023-03-10 6:24 ` Patrick Steinhardt [this message]
2023-03-10 8:37 ` Jeff King
2023-03-09 18:26 ` Taylor Blau
2023-03-09 18:48 ` Junio C Hamano
2023-03-09 18:49 ` Junio C Hamano
2023-03-10 6:52 ` [PATCH v2] " Patrick Steinhardt
2023-03-10 8:51 ` Jeff King
2023-03-10 11:49 ` Patrick Steinhardt
2023-03-10 13:20 ` Jeff King
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=ZArNJHMmPd8QCLwQ@ncase \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).