dovecot-2.0: sdbox: Fixed race condition when one session opens ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Nov 15 17:19:18 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/dbcbf6a46710
changeset: 12414:dbcbf6a46710
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 15 15:19:13 2010 +0000
description:
sdbox: Fixed race condition when one session opens a mailbox while another is still creating it.
This happened mostly when nonexistent INBOX was being opened by multiple
sessions at the same time.

diffstat:

 src/lib-storage/index/dbox-single/sdbox-storage.c |  17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diffs (27 lines):

diff -r 67fbf09d3fa5 -r dbcbf6a46710 src/lib-storage/index/dbox-single/sdbox-storage.c
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c	Wed Nov 10 16:09:14 2010 +0000
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c	Mon Nov 15 15:19:13 2010 +0000
@@ -228,8 +228,21 @@
 		return -1;
 
 	/* get/generate mailbox guid */
-	if (sdbox_read_header(mbox, &hdr, TRUE) < 0)
-		memset(&hdr, 0, sizeof(hdr));
+	if (sdbox_read_header(mbox, &hdr, FALSE) < 0) {
+		/* it's possible that this mailbox is just now being created
+		   by another process. lock it first and see if the header is
+		   available then. */
+		struct mail_index_sync_ctx *sync_ctx;
+		struct mail_index_view *view;
+		struct mail_index_transaction *trans;
+
+		if (mail_index_sync_begin(box->index, &sync_ctx,
+					  &view, &trans, 0) > 0)
+			(void)mail_index_sync_commit(&sync_ctx);
+
+		if (sdbox_read_header(mbox, &hdr, TRUE) < 0)
+			memset(&hdr, 0, sizeof(hdr));
+	}
 
 	if (mail_guid_128_is_empty(hdr.mailbox_guid)) {
 		/* regenerate it */


More information about the dovecot-cvs mailing list