From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 849CD6DE022F for ; Tue, 27 Feb 2018 14:51:55 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[AWL=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id falMLtZttUyT for ; Tue, 27 Feb 2018 14:51:54 -0800 (PST) X-Greylist: delayed 457 seconds by postgrey-1.36 at arlo; Tue, 27 Feb 2018 14:51:54 PST Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by arlo.cworth.org (Postfix) with ESMTPS id 667096DE01FF for ; Tue, 27 Feb 2018 14:51:54 -0800 (PST) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7E2D41F404; Tue, 27 Feb 2018 22:44:14 +0000 (UTC) Date: Tue, 27 Feb 2018 22:44:14 +0000 From: Eric Wong To: notmuch@notmuchmail.org Subject: notmuch modifies DB while iterating? Message-ID: <20180227224414.GA31804@dcvr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailman-Approved-At: Tue, 27 Feb 2018 16:09:50 -0800 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Feb 2018 22:51:55 -0000 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 add-message.cc While the Xapian::PostingIterator for loser is iterating, the Xapian DB is being modified by replace_document via _notmuch_message_sync. 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: https://public-inbox.org/meta/20180227221302.7308-1-e@80x24.org/raw 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 https://yhbt.net/skel.bug.perl and 81M gzipped dataset which reproduces the problem at https://yhbt.net/skel.bug.gz (each line is: MID [REFERENCES-SEPARATED-BY-SPACES]) Usage: For failure: curl https://yhbt.net/skel.bug.gz | zcat | perl -w /path/to/skel.bug.perl For success: curl https://yhbt.net/skel.bug.gz | zcat | \ BATCH_SIZE=1000 perl -w /path/to/skel.bug.perl