Problem/Motivation

TransactionManagerBase::processPostTransactionCallbacks() checks $this->getConnectionTransactionState() inside the foreach loop, once per callback. If an earlier callback starts a transaction of its own and rolls it back, the connection state changes to rolled back, and every later callback is passed FALSE even though the outer transaction committed.

Core's cache tag checksum and cache backends that defer deletes until commit run in these callbacks, so getting FALSE drops invalidations and deletes for committed changes and leaves other requests reading stale cached entities.

I hit this on Drupal 11.3, and it's still on main and 11.x. It's the other half of #3447097 (where a callback starting its own transaction loses its callbacks) and was also noted in a comment on #3634304. Note that #3634130 has a different trigger (two root transactions with retained objects) and this doesn't fix that one.

Steps to reproduce

  1. Start a root transaction and add two post-transaction callbacks.
  2. In the first callback, start a transaction and call rollBack().
  3. Commit the outer transaction with commitOrRelease() and let it go out of scope.
  4. The second callback gets FALSE instead of TRUE.

Proposed resolution

In TransactionManagerBase::processPostTransactionCallbacks(), work out the outcome once from getConnectionTransactionState() (ClientConnectionTransactionState::Committed or ClientConnectionTransactionState::Voided) before the loop and pass that boolean to every callback.

I'm opening an MR against main with the fix and a kernel test (testRootTransactionEndCallbackAfterCallbackRollback in TransactionTest) using explicit commitOrRelease(). The test fails on main and 11.x without the fix.

Locally on SQLite (PHP 8.5) I ran TransactionTest, the sqlite driver TransactionTest, EndOfTransactionQueriesTest, DatabaseBackendTagTest, DeleteTruncateTest, and the TransactionManagerTest and ConnectionTest unit tests. Everything passes. I haven't run MySQL or PostgreSQL locally.

Remaining tasks

  • Review MR
  • Backport to 11.x (the same change applies there)

I used AI tools to help track this down and draft the fix; I reviewed and tested it myself.

Issue fork drupal-3641682

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

teppy created an issue. See original summary.

teppy’s picture

Status: Active » Needs review