]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
sdbox: Fixed race condition when one session opens a mailbox while another is still...
authorTimo Sirainen <tss@iki.fi>
Mon, 15 Nov 2010 15:19:13 +0000 (15:19 +0000)
committerTimo Sirainen <tss@iki.fi>
Mon, 15 Nov 2010 15:19:13 +0000 (15:19 +0000)
This happened mostly when nonexistent INBOX was being opened by multiple
sessions at the same time.

src/lib-storage/index/dbox-single/sdbox-storage.c

index 80bfc36586e335d88e25232900622cfe42d5313c..ae4e6cbd4a7aa5d1a96df92a6e9322fbffc22d98 100644 (file)
@@ -228,8 +228,21 @@ static int sdbox_mailbox_open(struct mailbox *box)
                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 */