Problem/Motivation
This is exactly the same behavior described in this issue
https://www.drupal.org/project/drupal/issues/3507999 related to 10.4x
When launching phpunit tests that uses databases calls, it ends with a TypeError, basically because Drupal try to do some transaction cleanup at the end of the script execution using a database connection that had already been destroyed by phpunit at the end of its test suite.
Steps to reproduce
Just launch phpunit tests
Proposed resolution
I propose to add a test checking the availability of the database connection before launching the unpile task in the Transaction::__destruct() method in order to avoid errors in that particular case.
API changes
Drupal\Core\Database\Connection
Add a method hasClientConnection() to Drupal\Core\Database\Connection in order to have a mean to know if the object is available or not (regardless of this problem it seems wise to me to have this method)
test of the client's connection avaibility
Implement a test of the connection avaibility using this method either in
Drupal\Core\Database\Transaction::__destruct() method to avoid launching unpile
or more deeper in Drupal\Core\Cache\DatabaseCacheTagsChecksum::doInvalidateTags (which is the where the problem really occurs).
Issue fork drupal-3538834
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
Comment #2
mondrakeCan you check if #3406985: Convert all transactions in core to use explicit ::commitOrRelease() solves the problem?
Comment #3
ceonizm commentedComment #5
ceonizm commented@mondrake
I've cloned #3406985, copied my module into and tested to launch phpunit on my kernel tests and I can confirm you I also don't get the error with it.
Comment #6
ceonizm commentedComment #7
smustgrave commentedThanks for working on this. MR should point to 11.x as the current development branch
Comment #8
ceonizm commentedComment #9
smustgrave commented#7 still stands. And just going off the title our pipelines would be failing right?
Comment #10
mondrakeIf #3406985: Convert all transactions in core to use explicit ::commitOrRelease() fixes the issue, I would not pursue this. Under normal circumstances, there should not be the need to check that the client connection is active.