]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts-flatcurve: Fix deadlock in flatcurve indexing
authorMarco Bettini <marco.bettini@open-xchange.com>
Wed, 5 Feb 2025 16:12:35 +0000 (16:12 +0000)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:39 +0000 (12:34 +0200)
The deadlock was caused by not releasing soon enough the writable database,
causing the search process and the indexer process to conflict

src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc

index 0069317b0a3c5412f45b8bd45221d8dffa8e0870..e24a81821d8dc162236cbb78e0769a5cbab972b4 100644 (file)
@@ -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)",