Re: [PATCH] Actually close the xapian database in notmuch_database_close
authorAustin Clements <amdragon@MIT.EDU>
Thu, 1 Mar 2012 18:11:41 +0000 (13:11 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:07 +0000 (09:45 -0800)
15/c10187874ae25090de6efa22efeec482244efa [new file with mode: 0644]

diff --git a/15/c10187874ae25090de6efa22efeec482244efa b/15/c10187874ae25090de6efa22efeec482244efa
new file mode 100644 (file)
index 0000000..0948c2e
--- /dev/null
@@ -0,0 +1,136 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id ACCF2431FAF\r
+       for <notmuch@notmuchmail.org>; Thu,  1 Mar 2012 10:11:51 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id kLYa-Tvqif06 for <notmuch@notmuchmail.org>;\r
+       Thu,  1 Mar 2012 10:11:48 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
+       [18.7.68.37])\r
+       by olra.theworths.org (Postfix) with ESMTP id 03FB9431FAE\r
+       for <notmuch@notmuchmail.org>; Thu,  1 Mar 2012 10:11:47 -0800 (PST)\r
+X-AuditID: 12074425-b7f4a6d0000008e0-d3-4f4fbbe36361\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id D3.66.02272.3EBBF4F4; Thu,  1 Mar 2012 13:11:47 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q21IBhnl025827; \r
+       Thu, 1 Mar 2012 13:11:44 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q21IBf9R025475\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 1 Mar 2012 13:11:43 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1S3ATd-0001PR-JP; Thu, 01 Mar 2012 13:11:41 -0500\r
+Date: Thu, 1 Mar 2012 13:11:41 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Justus Winter <4winter@informatik.uni-hamburg.de>\r
+Subject: Re: [PATCH] Actually close the xapian database in\r
+       notmuch_database_close\r
+Message-ID: <20120301181141.GA4797@mit.edu>\r
+References:\r
+ <1330507157-22859-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
+       <1330507157-22859-2-git-send-email-4winter@informatik.uni-hamburg.de>\r
+       <20120229154833.GB772@mit.edu> <20120229211922.GQ24964@survex.com>\r
+       <20120229221754.GD772@mit.edu>\r
+       <20120301065930.5076.72748@thinkbox.jade-hamburg.de>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <20120301065930.5076.72748@thinkbox.jade-hamburg.de>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFupjleLIzCtJLcpLzFFi42IR4hRV1n2829/foPOGsMXs1h9MFtdvzmS2\r
+       uL/8PasDs8fE86fZPJ6tusXssW7nH/YA5igum5TUnMyy1CJ9uwSujKVTnrEXdIhU/F5+mamB\r
+       8Qd/FyMnh4SAicTys7PZIWwxiQv31rN1MXJxCAnsY5S4feIrC4SznlFi9vwHzBDOCSaJi2/n\r
+       sEM4Sxglrh7uZQbpZxFQkXjWOQHMZhPQkNi2fzkjiC0iYCqx4cEDsB3MApYSV2dMYwWxhQWC\r
+       JU5NPs0GYvMKaEscnn+XBcQWEtjBJLHvTSREXFDi5MwnLBC9WhI3/r1k6mLkALKlJZb/4wAJ\r
+       cwo4SrRumghWIgp0wpST29gmMArNQtI9C0n3LITuBYzMqxhlU3KrdHMTM3OKU5N1i5MT8/JS\r
+       i3Qt9HIzS/RSU0o3MYKCnd1FdQfjhENKhxgFOBiVeHi9Jvr7C7EmlhVX5h5ilORgUhLlrd8J\r
+       FOJLyk+pzEgszogvKs1JLT7EKMHBrCTCK9UPlONNSaysSi3Kh0lJc7AoifNqar3zExJITyxJ\r
+       zU5NLUgtgsnKcHAoSfAqAqNaSLAoNT21Ii0zpwQhzcTBCTKcB2i4GkgNb3FBYm5xZjpE/hSj\r
+       opQ4ryhIQgAkkVGaB9cLS0avGMWBXhHmNQap4gEmMrjuV0CDmYAGL77sBzK4JBEhJdXAePYu\r
+       w4O1ZvPVHy3xyfk3YY1jbhPPw/y7cetOOu2xe1nQt/CJXKWWrssHFz4Gdf/qNe5nGZ+qLVUM\r
+       tr6/h3t2UnHG89N3uZ4fme3+bc7ifz/LH50V3MKe8LLrofmDW3pq2+ViZ7//r+NmayMd7HPl\r
+       1ZUXOcE1FxtzAoUZVRwea1cZLlXYVLfzqxJLcUaioRZzUXEiAB8BTUAhAwAA\r
+Cc: Olly Betts <olly@survex.com>, notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 01 Mar 2012 18:11:51 -0000\r
+\r
+Quoth Justus Winter on Mar 01 at  7:59 am:\r
+> Quoting Austin Clements (2012-02-29 23:17:54)\r
+> >Quoth Olly Betts on Feb 29 at  9:19 pm:\r
+> >> On Wed, Feb 29, 2012 at 10:48:33AM -0500, Austin Clements wrote:\r
+> >> > Quoth Justus Winter on Feb 29 at 10:19 am:\r
+> >> > > Formerly the xapian database object was deleted and closed in its\r
+> >> > > destructor once the object was garbage collected. Explicitly call\r
+> >> > > close() so that the database and the associated lock is released\r
+> >> > > immediately.\r
+> >> > \r
+> >> > Interesting.  Is this a bug in Xapian?  According to the docs,\r
+> >> > ~Database is supposed to close the database (if there are no other\r
+> >> > copies, which there shouldn't be), so this should be redundant with\r
+> >> > the delete notmuch->xapian_db a few lines down, but your experience\r
+> >> > obviously suggests that it isn't and I can't find the code path in\r
+> >> > Xapian that would close it in the destructor.\r
+> >> \r
+> >> Most Xapian API classes (including Database and WritableDatabase) just\r
+> >> hold a reference-counted pointer, and so it's the destructor of the\r
+> >> reference-counted object which closes the database.  If "PIMPL" means\r
+> >> anything to you, that's what we have here.\r
+> >> \r
+> >> Some other API classes objects (such as PostingIterator) internally hold\r
+> >> a reference to the database they are using, so calling close()\r
+> >> explicitly is useful if you don't want to have to worry about such\r
+> >> objects still existing and holding onto references which keep the\r
+> >> database open.\r
+> >\r
+> >Makes sense.  Justus, could you add a comment to your patch explaining\r
+> >that we explicitly close the database because there may be other\r
+> >objects with references to it that would keep it open?\r
+> \r
+> I thought I did, I'm not a native speaker though, so if you want to\r
+> reword my message be my guest ;)\r
+\r
+Sorry, I meant a code comment.  Perhaps something like,\r
+\r
+/* Many Xapian objects (and thus notmuch objects) hold references to\r
+ * the database, so merely deleting the database may not suffice to\r
+ * close it.  Thus, we explicitly close it here. */\r
+\r
+> >Also, since close could throw an exception, it should get wrapped in a\r
+> >try/catch like flush currently is.\r
+> \r
+> My interpretation of [0] was that Xapian::Database::close() does not\r
+> throw any exceptions.\r
+\r
+Olly mentioned on IRC that it can throw an exception (because, for\r
+example, close calls flush).\r
+\r
+> Cheers,\r
+> Justus\r
+> \r
+> 0: http://xapian.org/docs/apidoc/html/classXapian_1_1Database.html#59f5f8b137723dcaaabdbdccbc0cf1eb\r