From c7d7bc16348d183329ab923bb1b40eb2eac16805 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 8 Jul 2019 18:56:12 +0300 Subject: [PATCH] lib-index: After recreating cache, make sure offsets are immediately updated to map They were most likely refreshed anyway before the next cache usage, but this caused an assert-crash if the dovecot.index was also recreated in the same sync. Broken by e31b0637d8788885a71db2def5743ebf14c698f3 Fixes: Panic: file mail-index-write.c: line 138 (mail_index_write): assertion failed: (file->hdr.prev_file_offset == hdr->log_file_head_offset) --- src/lib-index/mail-index-sync.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib-index/mail-index-sync.c b/src/lib-index/mail-index-sync.c index a133552097..641ab7be6f 100644 --- a/src/lib-index/mail-index-sync.c +++ b/src/lib-index/mail-index-sync.c @@ -937,6 +937,15 @@ int mail_index_sync_commit(struct mail_index_sync_ctx **_ctx) /* can't really do anything if index commit fails */ (void)mail_index_transaction_commit(&cache_trans); mail_cache_compress_unlock(&cache_lock); + /* Make sure the newly committed cache record offsets + are updated to the current index. This is important + if the dovecot.index gets recreated below, because + rotation of dovecot.index.log also re-maps the index + to make sure everything is up-to-date. But if it + wasn't, mail_index_write() will just assert-crash + because log_file_head_offset changed. */ + if (mail_index_map(ctx->index, MAIL_INDEX_SYNC_HANDLER_FILE) <= 0) + ret = -1; } } -- 2.47.3