From: Kevin Boulain <kevin@boula.in>
To: notmuch@notmuchmail.org
Cc: Kevin Boulain <kevin@boula.in>
Subject: [PATCH 1/2] test: showcase thread-unsafe s-expression query parser
Date: Mon, 3 Apr 2023 22:31:45 +0200 [thread overview]
Message-ID: <20230403203146.39749-1-kevin@boula.in> (raw)
The test fails quite reliably for me:
T810-tsan: Testing run code with TSan enabled against the library
PASS create
PASS query
FAIL sexp query
--- T810-tsan.3.EXPECTED 2023-04-03 19:53:04.400771102 +0000
+++ T810-tsan.3.OUTPUT 2023-04-03 19:53:04.402771109 +0000
@@ -1,2 +1,44 @@
== stdout ==
== stderr ==
+==================
+WARNING: ThreadSanitizer: data race (pid=21372)
+ Read of size 4 at 0x7b1000000188 by thread T2:
+ #0 Xapian::Internal::intrusive_ptr<Xapian::Query::Internal>::intrusive_ptr(Xapian::Internal::intrusive_ptr<Xapian::Query::Internal> const&) .../xapian/intrusive_ptr.h:107 (libnotmuch.so.5+0x3017b)
+ #1 Xapian::Query::Query(Xapian::Query const&) .../xapian/query.h:328 (libnotmuch.so.5+0x2fcbe)
+ #2 _sexp_to_xapian_query lib/parse-sexp.cc:707 (libnotmuch.so.5+0x43f1f)
+ #3 _notmuch_sexp_string_to_xapian_query(_notmuch_database*, char const*, Xapian::Query&) lib/parse-sexp.cc:729 (libnotmuch.so.5+0x44207)
+ #4 _notmuch_query_ensure_parsed_sexpr lib/query.cc:240 (libnotmuch.so.5+0x2c59e)
+ #5 _notmuch_query_ensure_parsed lib/query.cc:258 (libnotmuch.so.5+0x2c646)
+ #6 _notmuch_query_search_documents lib/query.cc:362 (libnotmuch.so.5+0x2cc0e)
+ #7 notmuch_query_search_messages lib/query.cc:350 (libnotmuch.so.5+0x2cb76)
+ #8 thread CWD/test2.c:17 (test2+0x4012f4)
+
+ Previous write of size 4 at 0x7b1000000188 by thread T1:
+ #0 Xapian::Internal::intrusive_ptr<Xapian::Query::Internal>::intrusive_ptr(Xapian::Internal::intrusive_ptr<Xapian::Query::Internal> const&) .../xapian/intrusive_ptr.h:107 (libnotmuch.so.5+0x3018e)
+ #1 Xapian::Query::Query(Xapian::Query const&) .../xapian/query.h:328 (libnotmuch.so.5+0x2fcbe)
+ #2 _sexp_to_xapian_query lib/parse-sexp.cc:707 (libnotmuch.so.5+0x43f1f)
+ #3 _notmuch_sexp_string_to_xapian_query(_notmuch_database*, char const*, Xapian::Query&) lib/parse-sexp.cc:729 (libnotmuch.so.5+0x44207)
+ #4 _notmuch_query_ensure_parsed_sexpr lib/query.cc:240 (libnotmuch.so.5+0x2c59e)
+ #5 _notmuch_query_ensure_parsed lib/query.cc:258 (libnotmuch.so.5+0x2c646)
+ #6 _notmuch_query_search_documents lib/query.cc:362 (libnotmuch.so.5+0x2cc0e)
+ #7 notmuch_query_search_messages lib/query.cc:350 (libnotmuch.so.5+0x2cb76)
+ #8 thread CWD/test2.c:17 (test2+0x4012f4)
+
+ Location is heap block of size 56 at 0x7b1000000180 allocated by main thread:
+ #0 operator new(unsigned long) <null> (libtsan.so.2+0x8ba83)
+ #1 Xapian::Query::Query(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int) <null> (libxapian.so.30+0x9f200)
+ #2 __static_initialization_and_destruction_0(int, int) <null> (libxapian.so.30+0xa27ac)
+ #3 _GLOBAL__sub_I_query.cc <null> (libxapian.so.30+0xa286d)
+ #4 call_init <null> (ld-linux-x86-64.so.2+0x5e1d)
+
+ Thread T2 (tid=21375, running) created by main thread at:
+ #0 pthread_create <null> (libtsan.so.2+0x62de6)
+ #1 main CWD/test2.c:24 (test2+0x4013ba)
+
+ Thread T1 (tid=21374, running) created by main thread at:
+ #0 pthread_create <null> (libtsan.so.2+0x62de6)
+ #1 main CWD/test2.c:23 (test2+0x401380)
+
+SUMMARY: ThreadSanitizer: data race .../xapian/intrusive_ptr.h:107 in Xapian::Internal::intrusive_ptr<Xapian::Query::Internal>::intrusive_ptr(Xapian::Internal::intrusive_ptr<Xapian::Query::Internal> const&)
+==================
+ThreadSanitizer: reported 1 warnings
---
test/T810-tsan.sh | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/test/T810-tsan.sh b/test/T810-tsan.sh
index 7e877b27..c9008c6b 100755
--- a/test/T810-tsan.sh
+++ b/test/T810-tsan.sh
@@ -89,4 +89,44 @@ cat <<EOF > EXPECTED
EOF
test_expect_equal_file EXPECTED OUTPUT
+if [ $NOTMUCH_HAVE_SFSEXP -eq 1 ]; then
+ test_begin_subtest "sexp query"
+ test_subtest_known_broken
+ test_C ${MAIL_DIR} ${MAIL_DIR}-2 <<EOF
+#include <notmuch-test.h>
+#include <pthread.h>
+
+void *thread (void *arg) {
+ char *mail_dir = arg;
+ notmuch_database_t *db;
+ /*
+ * Query generation from s-expression used the tread-unsafe
+ * Xapian::Query::MatchAll.
+ */
+ EXPECT0(notmuch_database_open_with_config (mail_dir,
+ NOTMUCH_DATABASE_MODE_READ_ONLY,
+ NULL, NULL, &db, NULL));
+ notmuch_query_t *query;
+ EXPECT0(notmuch_query_create_with_syntax (db, "(from *)", NOTMUCH_QUERY_SYNTAX_SEXP, &query));
+ notmuch_messages_t *messages;
+ EXPECT0(notmuch_query_search_messages (query, &messages));
+ return NULL;
+}
+
+int main (int argc, char **argv) {
+ pthread_t t1, t2;
+ EXPECT0(pthread_create (&t1, NULL, thread, argv[1]));
+ EXPECT0(pthread_create (&t2, NULL, thread, argv[2]));
+ EXPECT0(pthread_join (t1, NULL));
+ EXPECT0(pthread_join (t2, NULL));
+ return 0;
+}
+EOF
+ cat <<EOF > EXPECTED
+== stdout ==
+== stderr ==
+EOF
+ test_expect_equal_file EXPECTED OUTPUT
+fi
+
test_done
next reply other threads:[~2023-04-03 20:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-03 20:31 Kevin Boulain [this message]
2023-04-03 20:31 ` [PATCH 2/2] lib: thread-safe s-expression query parser Kevin Boulain
2023-07-22 19:06 ` David Bremner
2023-08-27 12:31 ` [PATCH v2 1/2] test: showcase thread-unsafe " Kevin Boulain
2023-09-19 10:30 ` David Bremner
2023-08-27 12:31 ` [PATCH v2 2/2] lib: thread-safe " Kevin Boulain
2024-07-25 10:23 ` David Bremner
2023-08-27 12:33 ` [PATCH " Kevin Boulain
2023-07-22 18:48 ` [PATCH 1/2] test: showcase thread-unsafe " David Bremner
2023-07-23 13:23 ` Michael J Gruber
2023-07-23 14:03 ` David Bremner
2023-08-06 10:05 ` Kevin Boulain
2023-08-06 12:01 ` David Bremner
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
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230403203146.39749-1-kevin@boula.in \
--to=kevin@boula.in \
--cc=notmuch@notmuchmail.org \
/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.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
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 read-only IMAP folder(s) and NNTP newsgroup(s).