From: Jeff King <peff@peff.net>
To: Johan Herland <johan@herland.net>
Cc: Duy Nguyen <pclouds@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] sha1_file.c:create_tmpfile(): Fix race when creating loose object dirs
Date: Fri, 18 Oct 2013 15:05:37 -0400 [thread overview]
Message-ID: <20131018190537.GB11040@sigill.intra.peff.net> (raw)
In-Reply-To: <CALKQrgcc6gXcthgZgrGS6YA0b8KmnaG=WO=Eu_YQc9pgjRRj6Q@mail.gmail.com>
On Fri, Oct 18, 2013 at 05:41:54PM +0200, Johan Herland wrote:
> (c) mkdir() fails with EEXIST, i.e. we lost the race. We do the
> adjust_shared_perms() which might fail (-> abort) or succeed, and we
> then _retry_ the git_mkstemp_mode(). There is no case where the
> "whatever" that happened between the first git_mkstemp_mode() and
> mkdir() will have a different outcome (create_tmpfile() failing or
> suceeding) than if it had happened _before_ the first
> git_mkstemp_mode().
I think your (c) is fine as long as adjust_shared_perms() is idempotent,
as we will run it twice (one for each side of the race). But from my
reading, I think it is.
I was almost tempted to say "we do not even need to run
adjust_shared_perm twice", but we do, or we risk another race: one side
loses the mkdir race, but wins the open() race, and writes to a
wrong-permission directory. Of course, that should not matter unless the
racers are two different users (in a shared repo), and in that case, we
wins the adjust_shared_perm race, but does not have permission to change
the mode.
> And it is not our responsibility to control what
> other/unrelated processes might end up doing with directories inside
> .git/objects/...
Agreed. We already leave a wrong-permission directory in place if it
existed before we started create_tmpfile. The code before your patch,
when racing with such a wrong-directory creator, would abort the
tmpfile. Now it will correct the permissions. Either behavior seems fine
to me (yours actually seems better, but the point is that it does not
matter because they are dwarfed by the non-race cases where the
directory is already sitting there).
-Peff
next prev parent reply other threads:[~2013-10-18 19:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-18 13:17 [PATCH] sha1_file.c:create_tmpfile(): Fix race when creating loose object dirs Johan Herland
2013-10-18 13:53 ` Eric Sunshine
2013-10-18 14:52 ` Johan Herland
2013-10-18 15:58 ` Eric Sunshine
2013-10-18 13:55 ` Duy Nguyen
2013-10-18 14:00 ` Duy Nguyen
2013-10-18 15:41 ` Johan Herland
2013-10-18 19:05 ` Jeff King [this message]
2013-10-18 19:24 ` Junio C Hamano
2013-10-18 23:45 ` Johan Herland
2013-10-19 2:53 ` Jeff King
2013-10-22 18:09 ` Junio C Hamano
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=20131018190537.GB11040@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johan@herland.net \
--cc=pclouds@gmail.com \
/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