git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] grep: take the read-lock when adding a submodule

From
BWBrandon Williams <bmwill@google.com>
Date
Nov 1, 2017, 20:55 UTC
Message-ID
<20171101205522.GA188245@google.com>
In-Reply-To
<20171101204506.5481-1-martin.agren@gmail.com>
On 11/01, Martin Ågren wrote:
Show 15 quoted lines
> 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!
Show 21 quoted lines
> 
>  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
Previous: Martin ÅgrenNext: Jeff King
Message 6 of 7 in “grep: turn off threading when recursing submodules”
  1. grep: turn off threading when recursing submodulesMartin Ågren, Oct 19, 2017
  2. Brandon WilliamsOct 19, 2017
  3. Jeff KingOct 19, 2017
  4. Martin ÅgrenOct 19, 2017
  5. grep: take the read-lock when adding a submoduleMartin Ågren, Nov 1, 2017
  6. Brandon WilliamsNov 1, 2017
  7. Jeff KingNov 1, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.