From: "Martin Ågren" <martin.agren@gmail.com>
To: git@vger.kernel.org
Cc: Brandon Williams <bmwill@google.com>, Jeff King <peff@peff.net>
Subject: [PATCH v2] grep: take the read-lock when adding a submodule
Date: Wed, 1 Nov 2017 21:45:06 +0100 [thread overview]
Message-ID: <20171101204506.5481-1-martin.agren@gmail.com> (raw)
In-Reply-To: <CAN0heSpxJDxmSXu=P0stq+CsKVqjsvOnjDpOoMT9GdWxeZU2Pw@mail.gmail.com>
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.
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
next prev parent reply other threads:[~2017-11-01 20:45 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 ` Martin Ågren [this message]
2017-11-01 20:55 ` [PATCH v2] grep: take the read-lock when adding a submodule Brandon Williams
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=20171101204506.5481-1-martin.agren@gmail.com \
--to=martin.agren@gmail.com \
--cc=bmwill@google.com \
--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).