From e22ac7474fb36e3e3dcfeb70ea5f54ea812aa2d0 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 15 Nov 2010 15:19:13 +0000 Subject: [PATCH] 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. --- .../index/dbox-single/sdbox-storage.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index 80bfc36586..ae4e6cbd4a 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -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 */ -- 2.47.3