changeset 22863:792f2b19851b

lib-storage: mailbox_list_index_handle_corruption() - Lock mailbox list while rebuilding This guards against simultaneous mailbox create/delete/rename.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 19 Feb 2018 12:54:53 +0200
parents dfa00b3e819f
children 4e340516a8ce
files src/lib-storage/list/mailbox-list-index.c
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/list/mailbox-list-index.c	Mon Feb 19 12:53:46 2018 +0200
+++ b/src/lib-storage/list/mailbox-list-index.c	Mon Feb 19 12:54:53 2018 +0200
@@ -627,7 +627,18 @@
 		return 0;
 	ilist->handling_corruption = TRUE;
 
-	ret = list_handle_corruption_locked(list, reason);
+	/* Perform the rebuilding locked. Note that if we're here because
+	   INBOX wasn't found, this may be because another process is in the
+	   middle of creating it. Waiting for the lock here makes sure that
+	   we don't start rebuilding before it's finished. In that case the
+	   rebuild is a bit unnecessary, but harmless (and avoiding the rebuild
+	   just adds extra code complexity). */
+	if (mailbox_list_lock(list) < 0)
+		ret = -1;
+	else {
+		ret = list_handle_corruption_locked(list, reason);
+		mailbox_list_unlock(list);
+	}
 	ilist->handling_corruption = FALSE;
 	return ret;
 }