From: Marco Bettini Date: Wed, 5 Feb 2025 16:12:35 +0000 (+0000) Subject: fts-flatcurve: Fix deadlock in flatcurve indexing X-Git-Tag: 2.4.1~233 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=599095da622a23c4245ddb8a266fc12125b48f22;p=thirdparty%2Fdovecot%2Fcore.git fts-flatcurve: Fix deadlock in flatcurve indexing The deadlock was caused by not releasing soon enough the writable database, causing the search process and the indexer process to conflict --- diff --git a/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc b/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc index 0069317b0a..e24a81821d 100644 --- a/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc +++ b/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc @@ -1412,9 +1412,15 @@ fts_flatcurve_xapian_close_db(struct flatcurve_fts_backend *backend, e_error(backend->event, "%s", error); else { const char *fname = p_strdup(x->pool, xdb->dbpath->fname); - enum flatcurve_xapian_db_close flags = + /* When rotating, we need to open RW for Xapian to + * create the new shard, but immediately close the + * RW handle since there is no imminent write, and + * failure to do so may cause locking issues with + * other processes. */ + const auto flags = (enum flatcurve_xapian_db_close) - (opts & FLATCURVE_XAPIAN_DB_CLOSE_MBOX); + ((opts & FLATCURVE_XAPIAN_DB_CLOSE_MBOX) | + FLATCURVE_XAPIAN_DB_CLOSE_WDB); if (fts_flatcurve_xapian_create_current( backend, flags, &error) < 0) e_error(backend->event, "Error rotating DB (%s)",