notmuch modifies DB while iterating?

classic Classic list List threaded Threaded
1 message Options
Eric Wong Eric Wong
Reply | Threaded
Open this post in threaded view

notmuch modifies DB while iterating?

Hello, I'm neither a notmuch user or proficient in C++.

However, I noticed a bug while working on public-inbox (in Perl)
which shares Xapian thread linking logic with notmuch, and I
suspect notmuch is affected by the same problem as public-inbox.

The problem is in the _merge_threads function in
While the Xapian::PostingIterator for loser is iterating, the
Xapian DB is being modified by replace_document via

This was causing DatabaseCorruptError exceptions in public-inbox
with my dataset.

I fixed it in public-inbox by stashing docid scalars into a
Perl array while iterating with the PostingIterator, and then
doing lookups + replacements independently of the
PostingIterator by iterating through the Perl array:

I initially thought this was a bug in the glass backend, but
I've also hit it with chert.

I have a standalone Perl script to reproduce the bug at and 81M gzipped dataset which
reproduces the problem at



For failure:
  curl | zcat | perl -w /path/to/skel.bug.perl

For success:
  curl | zcat | \
        BATCH_SIZE=1000 perl -w /path/to/skel.bug.perl
notmuch mailing list
[hidden email]