Review main Ready for review Orphaned Breaking

89179[!!!][BUGFIX] Prevent database deadlocks in Typo3DatabaseBackend::set()

Adam Koppe CR -2 V 0 Normal +238 −11 updated 04/22/26, 12:54

Commit message

Fix three undesired things that may happen if there are many concurrent
calls to Typo3DatabaseBackend::set() with the same cache entry
identifier:

- Multiple rows with the same cache entry identifier are inserted into
  the backing cache table. This is undesired as
  Typo3DatabaseBackend::get() only ever fetches the first
  row. Solve this by declaring the cache entry identifier the PRIMARY
  KEY of the table and removing the "id" column.

- Multiple rows with the same cache entry identifier and tag combination
  are inserted into the table backing the cache tags. This is undesired
  as Typo3DatabaseBackend::flushByTags() and
  Typo3DatabaseBackend::flushByTag() will list those cache entry
  identifiers multiple times in the IN part of the DELETE WHERE clause.
  Solve this by declaring the cache entry identifier and tag
  combination the PRIMARY KEY of the table and removing the "id" column.

- Database deadlock exceptions are thrown. Solve this for common
  Caching-API usage patterns by introducing an optimized cache set
  routine that enables re-use of existing rows in both cache backing
  tables. This depends on both PRIMARY KEY changes.

A full reproduction example is available online on GitHub:
https://github.com/adamkoppede/reproduce-deadlock-with-fluidtypo3-vhs-7-1

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 4
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/79/89179/4 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/79/89179/4 && git cherry-pick FETCH_HEAD

Review

  • Code review CR -2 Blocked
    • Stefan Bürk -2
  • Verified V 0 Needs a vote
    • core-ci +1 CI

Issues 1

Files 4

Review log 812

  1. Adam Koppe uploaded patch set 1 04/21/25, 21:45

  2. core-ci voted on patch set 1 V +1 04/21/25, 21:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77996

  3. Adam Koppe commented on patch set 1 04/21/25, 21:54

    Typo3DatabaseBackendCache.sql:5 Unresolved

    I found two issues when applying this patch to an existing TYPO3 v13 instance: 1. If there are multiple rows with the same cache entry identifier `cache:flush` is required before `database:updateschema safe` is possible. 2. `database:updateschema safe` changes the "id" field to `int(11) unsigned NOT NULL DEFAULT NULL` which breaks the Typo3DatabaseBackendCache implementation as the "id" field is never specified. I think there are two paths moving forward: 1. Introduce special handling for this specific migration. 2. Ignore issue 1 and fix `database:updateschema safe` to generally make deleted fields optional.
  4. Stefan Bürk commented on patch set 1 CR -2 04/22/25, 04:35

    Unresolved

    -2 to ensure that I have time to look onto this change
  5. Adam Koppe commented on patch set 1 04/22/25, 05:17

    Unresolved

    A changelog entry is also required for this breaking change. I guess the content would be something like "Table structure of database-based caches changed". And depending how https://review.typo3.org/c/Packages/TYPO3.CMS/+/89179/comment/b39ebf85_bc3abad5/ turns out upgrade instructions / what to do on errors during upgrade
  6. Adam Koppe commented on patch set 1 04/22/25, 05:37

    Typo3DatabaseBackend.php:139 Unresolved

    Should we also catch `\Doctrine\DBAL\Exception\UniqueConstraintViolationException` during both `INSERT`-s? That exception will be thrown if another concurrent Typo3DatabaseBackend::set() issues its `INSERT` before we issue our. If the exception happens we could just do nothing, as the concurrent Typo3DatabaseBackend::set() calls could have been ordered in a way where our (the throwing call) is ordered first and the other call immediate overwrites the cache entry afterwards.
  7. Adam Koppe updated the commit message in patch set 2 V +1 04/24/25, 20:02

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**")
  8. core-ci voted on patch set 2 V +1 04/24/25, 20:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/78149

  9. Simon Schaufelberger updated the commit message in patch set 3 V +1 11/07/25, 18:50

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**")
  10. core-ci voted on patch set 3 V -1 11/07/25, 18:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88671

  11. Adam Koppe uploaded patch set 4 V -1 04/22/26, 11:01

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**")
  12. core-ci voted on patch set 4 V +1 04/22/26, 12:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100892