changeset 21507:e14d3d07c47b

sdbox: Fix assert-crash on mailbox create race If another process created the mailbox at the same time, the mailbox_guid wasn't set and opening the mailbox assert-crashed: Panic: file mail-storage.c: line 1744 (mailbox_get_metadata): assertion failed: ((items & MAILBOX_METADATA_GUID) == 0 || !guid_128_is_empty(metadata_r->guid))
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 06 Feb 2017 18:34:05 +0200
parents 4e84b0d61d49
children 673a12afb3c5
files src/lib-storage/index/dbox-single/sdbox-storage.c
diffstat 1 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c	Tue Feb 07 21:07:54 2017 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c	Mon Feb 06 18:34:05 2017 +0200
@@ -373,6 +373,32 @@
 }
 
 static int
+sdbox_mailbox_create(struct mailbox *box,
+		     const struct mailbox_update *update, bool directory)
+{
+	struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
+	struct sdbox_index_header hdr;
+	bool need_resize;
+
+	if (dbox_mailbox_create(box, update, directory) < 0)
+		return -1;
+	if (directory || !guid_128_is_empty(mbox->mailbox_guid))
+		return 0;
+
+	/* another process just created the mailbox. read the mailbox_guid. */
+	if (sdbox_read_header(mbox, &hdr, FALSE, &need_resize) < 0) {
+		mail_storage_set_critical(box->storage,
+			"sdbox %s: Failed to read newly created dbox header",
+			mailbox_get_path(&mbox->box));
+		return -1;
+	}
+	memcpy(mbox->mailbox_guid, hdr.mailbox_guid,
+	       sizeof(mbox->mailbox_guid));
+	i_assert(!guid_128_is_empty(mbox->mailbox_guid));
+	return 0;
+}
+
+static int
 sdbox_mailbox_get_metadata(struct mailbox *box,
 			   enum mailbox_metadata_items items,
 			   struct mailbox_metadata *metadata_r)
@@ -448,7 +474,7 @@
 		sdbox_mailbox_open,
 		sdbox_mailbox_close,
 		index_storage_mailbox_free,
-		dbox_mailbox_create,
+		sdbox_mailbox_create,
 		dbox_mailbox_update,
 		index_storage_mailbox_delete,
 		index_storage_mailbox_rename,