From f2c44f8732a4731f405de3eb08138679c90dd388 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 23 Jul 2026 19:52:41 -0400 Subject: [PATCH] fix: Add row lock in documentUpdater (#13108) --- server/commands/documentUpdater.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/commands/documentUpdater.ts b/server/commands/documentUpdater.ts index 0a19209b31..028a8126e7 100644 --- a/server/commands/documentUpdater.ts +++ b/server/commands/documentUpdater.ts @@ -65,6 +65,19 @@ export default async function documentUpdater( const { transaction } = ctx.state; const cId = collectionId || document.collectionId; + // Serialize concurrent updates to the same document by taking a row-level + // lock before mutating. The wait is already bounded by the transaction's + // statement_timeout. + if (transaction) { + await Document.unscoped().findOne({ + attributes: ["id"], + where: { id: document.id }, + transaction, + lock: transaction.LOCK.UPDATE, + paranoid: false, + }); + } + if (title !== undefined) { document.title = title.trim(); }