From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: Jeff King <peff@peff.net>, git@vger.kernel.org
Subject: Re: [PATCH] refs: fix corruption by not correctly syncing packed-refs to disk
Date: Sun, 25 Dec 2022 20:25:59 +0900 [thread overview]
Message-ID: <xmqqtu1johbs.fsf@gitster.g> (raw)
In-Reply-To: Y6HYTt58iecdBEdw@coredump.intra.peff.net
Jeff King <peff@peff.net> writes:
> On Tue, Dec 20, 2022 at 03:52:14PM +0100, Patrick Steinhardt wrote:
>
>> And while we do the dance when writing the `packed-refs` file, there is
>> indeed one gotcha: we use a `FILE *` stream to write the temporary file,
>> but don't flush it before synchronizing it to disk. As a consequence any
>> data that is still buffered will not get synchronized and a crash of the
>> machine may cause corruption.
>
> The problem description makes sense, and so does your fix.
>
> Grepping for other uses of fsync_component(), this looks like the only
> buggy case (loose refs use write() directly, and most other files go via
> finalize_hashfile(), which does likewise).
> ...
> So given that this is the only affected site, it makes sense to just fix
> it for now and worry about a more generalized solution if we run into it
> again.
Sounds good.
This came from bc22d845 (core.fsync: new option to harden
references, 2022-03-11), before which we did not even fsync() the
file, so let me apply directly on top of that commit. Those who are
stuck on older versions of Git can choose to merge the result, even
though I may probably not bother merging it down to anything older
than 2.39 maintenance track.
Thanks.
prev parent reply other threads:[~2022-12-25 11:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-20 14:52 [PATCH] refs: fix corruption by not correctly syncing packed-refs to disk Patrick Steinhardt
2022-12-20 15:44 ` Jeff King
2022-12-25 11:25 ` Junio C Hamano [this message]
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=xmqqtu1johbs.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--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 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).