[DRAFT 0/1] lib: replace some uses of Query::MatchAll with a thread-safe alternative

Subject: [DRAFT 0/1] lib: replace some uses of Query::MatchAll with a thread-safe alternative

Date: Sat, 25 Feb 2023 18:46:00 +0100

To: notmuch@notmuchmail.org

Cc: Kevin Boulain

From: Kevin Boulain


Hey,

Here's a draft patch previously discussed in
https://nmbug.notmuchmail.org/nmweb/show/87ilfvq3bc.fsf%40boula.in

See the commit's message for more information.

Unfortunaly this only covers two third of the usages of
Xapian::Query::MatchAll, in lib/query.cc and lib/regexp-fields.cc.
lib/parse-sexp.cc has the rest of it but I don't believe it's worth to
change until sfsexp also becomes thread-safe (and s-expressions are
currently optional).

For example, globals are used:
https://github.com/mjsottile/sfsexp/blob/master/src/parser.c#L81
Which will lead to segfaults (null pointer dereference) in
pd_allocate:
  #0  0x00007fc19ce20861 in pd_allocate () at parser.c:283
  #1  0x00007fc19ce21778 in cparse_sexp (str=0x7fc194018c40 "(from )", len=7, lc=0x0) at parser.c:863
  #2  0x00007fc19ce20c50 in parse_sexp (s=0x7fc194018c40 "(from )", len=7) at parser.c:486
  #3  0x00007fc19ce6f8a8 in _notmuch_sexp_string_to_xapian_query (notmuch=0x7fc194003120, querystr=0x7fc194018bd0 "(from )", output=...) at lib/parse-sexp.cc:723
  #4  0x00007fc19ce5e93f in _notmuch_query_ensure_parsed_sexpr (query=0x7fc1940147b0) at lib/query.cc:240
  #5  0x00007fc19ce5e997 in _notmuch_query_ensure_parsed (query=0x7fc1940147b0) at lib/query.cc:258
  #6  0x00007fc19ce5ed89 in _notmuch_query_search_documents (query=0x7fc1940147b0, type=0x7fc19ce78af6 "mail", out=0x7fc19bd3bcc0) at lib/query.cc:362
  #7  0x00007fc19ce5ed2f in notmuch_query_search_messages (query=0x7fc1940147b0, out=0x7fc19bd3bcc0) at lib/query.cc:350
  ...
And looking at the function clearly shows this is due to a race
because it segfaults on an empty stack (l = NULL):
https://github.com/mjsottile/sfsexp/blob/master/src/parser.c#L283
When it just checked it wasn't:
https://github.com/mjsottile/sfsexp/blob/master/src/parser.c#L270

Thoughts? Should clients using the library gate every function call to
Notmuch behind a lock instead? I can also start a discussion in
sfsexp's issue tracker.

Kevin Boulain (1):
  lib: replace some uses of Query::MatchAll with thread-safe alternative

 configure            |  15 +++++-
 lib/query.cc         |   2 +-
 lib/regexp-fields.cc |   2 +-
 test/T810-tsan.sh    | 106 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 122 insertions(+), 3 deletions(-)
 create mode 100755 test/T810-tsan.sh

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: