Mercurial > dovecot > core-2.2
changeset 12414:dbcbf6a46710
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.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 15 Nov 2010 15:19:13 +0000 |
parents | 67fbf09d3fa5 |
children | 236ed6d5b391 |
files | src/lib-storage/index/dbox-single/sdbox-storage.c |
diffstat | 1 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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 */