--- /dev/null
+Return-Path: <jani@nikula.org>\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 E91D5431FC0\r
+ for <notmuch@notmuchmail.org>; Thu, 1 Jan 2015 10:22:00 -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 kwOSoCmIUgiI for <notmuch@notmuchmail.org>;\r
+ Thu, 1 Jan 2015 10:21:57 -0800 (PST)\r
+Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com\r
+ [209.85.212.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 806D4431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 1 Jan 2015 10:21:57 -0800 (PST)\r
+Received: by mail-wi0-f174.google.com with SMTP id h11so26827084wiw.1\r
+ for <notmuch@notmuchmail.org>; Thu, 01 Jan 2015 10:21:56 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id;\r
+ bh=0uSzEjuDOGI7a2nIRhECAFVYQEhm/l4emJvljfVRG9A=;\r
+ b=Lh1iw7qttnpROzfvKwvXkWmJMwO8B+uPQP9lh/tI4KJn1Hv9XgF3BAPpKNyRQVAsLg\r
+ ZLXgRGwJ+gJ9Wf/ZY8FXCjinnWPR4j9oOQ+PmWbX4fDGZBIvijF8qwQMg+Jar74iHxgv\r
+ q+jmTSzNC4e1XD3tXO7ACqiOJstr3fv0NgfN8qsnX7txuXIqJW51sKNa4TqGRX2mYfIw\r
+ bH12k7B1m6PqVV/kgsrvJgE5RSkQFIE/r+yzci8gtV4tRd/K/FDU5hrCQLJ3g7R8Hp6g\r
+ bmm3D1JGopuhpoYGIHcjl8uzKFIMVsahtIfzDHeojEfvS6MlqL1gRai/B5HDJ2dG5dN3\r
+ Sh7w==\r
+X-Gm-Message-State:\r
+ ALoCoQmJpAWME6es/3LeMYTA+0SElJR0+BjRGS9VnYiSKUZqpxJHcWuePcSg0b8XHGC+teEREdFr\r
+X-Received: by 10.194.175.69 with SMTP id by5mr139926544wjc.32.1420136516193; \r
+ Thu, 01 Jan 2015 10:21:56 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw2-58c371-91.dhcp.inet.fi.\r
+ [88.195.113.91])\r
+ by mx.google.com with ESMTPSA id lg7sm51493931wic.0.2015.01.01.10.21.55\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Thu, 01 Jan 2015 10:21:55 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] HACK: lib: add brute and ignorant handling of database lock\r
+ errors\r
+Date: Thu, 1 Jan 2015 20:22:03 +0200\r
+Message-Id: <1420136523-27100-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\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 Jan 2015 18:22:01 -0000\r
+\r
+From: Jani Nikula <jani.nikula@intel.com>\r
+\r
+Instead of failing at first try, back off for an increasing number of\r
+seconds, and only fail after three attempts.\r
+\r
+One of my notmuch installations that gets plenty of mail hits db\r
+locked exceptions quite often, and even more than before since I\r
+switched to using notmuch insert. These are quite annoying in the\r
+Emacs UI as there is virtually no error handling for tagging, and the\r
+tag change highlighting gets confused.\r
+\r
+This is a dirty hack, but for me it's much more preferrable to the the\r
+db locked exceptions. With the retries and increasing back-off timeout\r
+I hardly ever see the exceptions now.\r
+\r
+Maybe this inspires someone to fix this for real. ;)\r
+---\r
+ lib/database.cc | 19 +++++++++++++++++--\r
+ 1 file changed, 17 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 3601f9ded307..50063c55969b 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -819,8 +819,23 @@ notmuch_database_open (const char *path,\r
+ string last_thread_id;\r
+ \r
+ if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {\r
+- notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,\r
+- Xapian::DB_CREATE_OR_OPEN);\r
++ /*\r
++ * Brute and ignorant handling of database lock errors.\r
++ * Instead of failing at first try, back off for an\r
++ * increasing number of seconds.\r
++ */\r
++ for (unsigned int tries = 1; ! notmuch->xapian_db; tries++) {\r
++ try {\r
++ notmuch->xapian_db =\r
++ new Xapian::WritableDatabase (xapian_path,\r
++ Xapian::DB_CREATE_OR_OPEN);\r
++ } catch (const Xapian::DatabaseLockError &error) {\r
++ if (tries > 3)\r
++ throw;\r
++\r
++ sleep(tries);\r
++ }\r
++ }\r
+ } else {\r
+ notmuch->xapian_db = new Xapian::Database (xapian_path);\r
+ }\r
+-- \r
+2.1.4\r
+\r