Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 85C5B431FB6 for ; Sun, 6 Nov 2011 04:23:10 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A9sXZ9LNqsDT for ; Sun, 6 Nov 2011 04:23:09 -0800 (PST) Received: from plum.liegesta.at (plum.liegesta.at [83.169.17.237]) by olra.theworths.org (Postfix) with ESMTP id B0570429E21 for ; Sun, 6 Nov 2011 04:23:09 -0800 (PST) Received: from ambiguous-mid.liegesta.at (mk046207255168.a1.net [46.207.255.168]) (Authenticated sender: davrieb) by plum.liegesta.at (Postfix) with ESMTPA id 7FE1127B8259; Sun, 6 Nov 2011 13:23:08 +0100 (CET) Received: by ambiguous-mid.liegesta.at (Postfix, from userid 1000) id 4E0E91FF1E; Sun, 6 Nov 2011 12:23:06 +0100 (CET) From: David Riebenbauer To: Notmuch Mailing List Subject: [PATCH 1/3] notmuch-deliver: wait for the database to become unlocked Date: Sun, 6 Nov 2011 12:23:02 +0100 Message-Id: <1320578584-6642-2-git-send-email-davrieb@liegesta.at> X-Mailer: git-send-email 1.7.7.1 In-Reply-To: <1320578584-6642-1-git-send-email-davrieb@liegesta.at> References: <1320578584-6642-1-git-send-email-davrieb@liegesta.at> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Sun, 06 Nov 2011 12:23:10 -0000 If notmuch-deliver just gives up on a locked database this can result in mail bouncing. This patch makes it wait a given time and then retry to open the database. The wait time starts at a millisecond, and doubles every time the database is still locked, until an absolute maximum time of 10 minutes is reached. --- contrib/notmuch-deliver/src/main.c | 25 ++++++++++++++++++++++--- 1 files changed, 22 insertions(+), 3 deletions(-) diff --git a/contrib/notmuch-deliver/src/main.c b/contrib/notmuch-deliver/src/main.c index f7a4eaa..e30cbac 100644 --- a/contrib/notmuch-deliver/src/main.c +++ b/contrib/notmuch-deliver/src/main.c @@ -71,6 +71,9 @@ #define EX_CONFIG 78 #endif +#define MIN_UWAIT 1000 // 1 millisecond +#define MAX_UWAIT 600000000 // 10 minutes + static gboolean opt_create, opt_fatal, opt_folder, opt_version; static gboolean opt_verbose = FALSE; static gchar **opt_tags = NULL; @@ -428,10 +431,26 @@ main(int argc, char **argv) maildir = g_strdup(db_path); g_debug("Opening notmuch database `%s'", db_path); - db = notmuch_database_open(db_path, NOTMUCH_DATABASE_MODE_READ_WRITE); + gint32 wait_time = 0; + gint32 next_wait = MIN_UWAIT; + while ((db = notmuch_database_open(db_path, NOTMUCH_DATABASE_MODE_READ_WRITE)) == NULL) { + g_debug("Retrying to open database in %u microseconds", next_wait); + usleep(next_wait); + + next_wait *= 2; + if (wait_time + next_wait >= MAX_UWAIT) { + wait_time = next_wait - MAX_UWAIT; + if (wait_time <= 0) { + g_free(db_path); + if (db == NULL) + return EX_SOFTWARE; + } + } + + wait_time += next_wait; + } g_free(db_path); - if (db == NULL) - return EX_SOFTWARE; + if (notmuch_database_needs_upgrade(db)) { g_message("Upgrading database"); notmuch_database_upgrade(db, NULL, NULL); -- 1.7.7.1