Skip to content

fix: reuse transactions for document lock reads - #18421

Open
drewmt wants to merge 3 commits into
payloadcms:mainfrom
drewmt:fix/lock-read-transaction
Open

drewmt wants to merge 3 commits into
payloadcms:mainfrom
drewmt:fix/lock-read-transaction

Conversation

@drewmt

@drewmt drewmt commented Sep 30, 2026 •

Copy link
Copy Markdown

What?

Reuse the request transaction when reading document locks, including the bulk-delete lock check.

Why?

Concurrent updates and deletes can occupy every PostgreSQL pool connection with active transactions. The lock check currently reads outside those transactions and waits for another connection, preventing the writes from finishing and releasing their connections.

How?

Pass req to both lock queries, retaining the same MongoDB exception already used by lock cleanup. No API or schema changes.

Five PostgreSQL integration tests fill the real connection pool and exercise collection update, collection delete, global update, bulk delete, and rejection of a lock held by another user. They fail with connection timeouts before the change and pass afterward.

A separate regression covers payload.renameFile with a real PostgreSQL pool limited to one connection. It creates a local upload, renames it, and verifies the saved filename and file bytes. Removing the transaction-aware lock read causes a connection timeout at checkDocumentLockStatus; restoring it passes. This covers the single-call reproduction in the issue without changing rename behavior.

Validation:

  • Full document-lock suite plus the existing file-renaming suite on current main: 33 tests passed, 1 existing test skipped.
  • Scoped ESLint, Prettier and whitespace checks passed.
  • Initial validation on September 30 found identical fixture typecheck diagnostics with and without the production change. The additional collection REST rollback fixture could not initialize locally because PostGIS was unavailable. Neither check was rerun for this test-only follow-up.
  • PostgreSQL 15 was used for local validation. MongoDB, PGlite and the complete monorepo suite were not run.

This targets current main; the reported v3 path has the same missing request, while main also has the batched lock-read helper.

Fixes #18406

@drewmt drewmt changed the title fix(payload): reuse transactions for document lock reads fix: reuse transactions for document lock reads Sep 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

checkDocumentLockStatus reads locked documents without req, deadlocking the Postgres pool under concurrent update/delete

1 participant