unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [DRAFT 0/1] lib: replace some uses of Query::MatchAll with a thread-safe alternative
@ 2023-02-25 17:46 Kevin Boulain
  2023-02-25 17:46 ` [DRAFT 1/1] " Kevin Boulain
  2023-02-26 12:08 ` [DRAFT 0/1] " David Bremner
  0 siblings, 2 replies; 6+ messages in thread
From: Kevin Boulain @ 2023-02-25 17:46 UTC (permalink / raw)
  To: notmuch; +Cc: 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-31 11:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-25 17:46 [DRAFT 0/1] lib: replace some uses of Query::MatchAll with a thread-safe alternative Kevin Boulain
2023-02-25 17:46 ` [DRAFT 1/1] " Kevin Boulain
2023-02-26 12:18   ` David Bremner
2023-02-26 12:08 ` [DRAFT 0/1] " David Bremner
2023-03-02 17:59   ` [PATCH 1/1] " Kevin Boulain
2023-03-31 11:20     ` David Bremner

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).