From 8307b699bf536099c24e72261dbe4b3fc90992d4 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 3 Nov 2025 19:55:37 +0100 Subject: [PATCH] :bug: Remove a race condition on file export Caused when file is deleted in the middle of an exportation. The current export process is not transactional, and on file deletion several queries can start return not-found exception because of concurrent file deletion. With the changes on this PR we allow query deleted files internally on the exportation process and make it resilent to possible concurrent deletion. --- backend/src/app/binfile/common.clj | 2 +- backend/src/app/binfile/v3.clj | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/src/app/binfile/common.clj b/backend/src/app/binfile/common.clj index 1f6ab99cf2..cf8508caa0 100644 --- a/backend/src/app/binfile/common.clj +++ b/backend/src/app/binfile/common.clj @@ -550,7 +550,7 @@ [cfg data file-id] (let [library-ids (get-libraries cfg [file-id])] (reduce (fn [data library-id] - (if-let [library (get-file cfg library-id)] + (if-let [library (get-file cfg library-id :include-deleted? true)] (ctf/absorb-assets data (:data library)) data)) data diff --git a/backend/src/app/binfile/v3.clj b/backend/src/app/binfile/v3.clj index 682ddc74de..cf88f71551 100644 --- a/backend/src/app/binfile/v3.clj +++ b/backend/src/app/binfile/v3.clj @@ -228,6 +228,7 @@ (db/tx-run! cfg (fn [cfg] (cond-> (bfc/get-file cfg file-id {:realize? true + :include-deleted? true :lock-for-update? true}) detach? (-> (ctf/detach-external-references file-id) @@ -285,14 +286,12 @@ (let [file (cond-> (select-keys file bfc/file-attrs) (:options data) - (assoc :options (:options data)) + (assoc :options (:options data))) - :always - (dissoc :data)) - - file (cond-> file - :always - (encode-file)) + file (-> file + (dissoc :data) + (dissoc :deleted-at) + (encode-file)) path (str "files/" file-id ".json")] (write-entry! output path file))