All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brandon Williams <bmwill@google.com>
To: "Martin Ågren" <martin.agren@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH v2] grep: take the read-lock when adding a submodule
Date: Wed, 1 Nov 2017 13:55:22 -0700	[thread overview]
Message-ID: <20171101205522.GA188245@google.com> (raw)
In-Reply-To: <20171101204506.5481-1-martin.agren@gmail.com>

On 11/01, Martin Ågren wrote:
> With --recurse-submodules, we add each submodule that we encounter to
> the list of alternate object databases. With threading, our changes to
> the list are not protected against races. Indeed, ThreadSanitizer
> reports a race when we call `add_to_alternates_memory()` around the same
> time that another thread is reading in the list through
> `read_sha1_file()`.
> 
> Take the grep read-lock while adding the submodule. The lock is used to
> serialize uses of non-thread-safe parts of Git's API, including
> `read_sha1_file()`.
> 
> Helped-by: Brandon Williams <bmwill@google.com>
> Signed-off-by: Martin Ågren <martin.agren@gmail.com>
> ---
> Many thanks to Brandon for showing how this should have been done.

Of course! Happy to help :)

And this looks good, thanks for fixing my mistake!

> 
>  builtin/grep.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/builtin/grep.c b/builtin/grep.c
> index 2d65f27d0..5a6cfe6b4 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -431,7 +431,9 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
>  	 * store is no longer global and instead is a member of the repository
>  	 * object.
>  	 */
> +	grep_read_lock();
>  	add_to_alternates_memory(submodule.objectdir);
> +	grep_read_unlock();
>  
>  	if (oid) {
>  		struct object *object;
> -- 
> 2.15.0.415.gac1375d7e
> 

-- 
Brandon Williams

  reply	other threads:[~2017-11-01 20:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-19 19:07 [PATCH/RFC] grep: turn off threading when recursing submodules Martin Ågren
2017-10-19 19:26 ` Brandon Williams
2017-10-19 19:34   ` Jeff King
2017-10-19 19:50     ` Martin Ågren
2017-11-01 20:45       ` [PATCH v2] grep: take the read-lock when adding a submodule Martin Ågren
2017-11-01 20:55         ` Brandon Williams [this message]
2017-11-01 21:11         ` 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=20171101205522.GA188245@google.com \
    --to=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=martin.agren@gmail.com \
    --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 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.