python-notmuch crash with threads

Subject: python-notmuch crash with threads

Date: Thu, 01 Dec 2011 10:24:26 -0500

To: notmuch


From: James Westby


I've been seeing a race with python-notmuch, where it will crash due to
pointers being invalidated when threads are used.

I've attached a script which shows the problem some of the time. It's
about the smallest script I can make, but it's hampered by the fact that
making it simpler seems to make the race less likely, so it's hard to
know when it is gone.

The typical backtrace is:

Program terminated with signal 11, Segmentation fault.
#0  0x00007f7b19c34b59 in talloc_named_const () from /usr/lib/x86_64-linux-gnu/
(gdb) up
#1  0x00007f7b1a5f78dc in notmuch_query_search_threads (query=0x14001c70) at lib/
322	lib/ No such file or directory.
	in lib/
(gdb) p *query
Cannot access memory at address 0x14001c70

Where something is invalidating the pointer between creation in
db.create_query() and calling it in query.search_threads()

I've seen other similar things when using other code in the thread. talks about the
thread-safety of talloc, and I don't think it's any of those issues

Any suggestions for how to debug this further would be most welcome.