Possible issue with recursive locks
I've brought this over from pr 22013 because it needs to be discussed in gitlab before it can be reviewed as a PR & hence doesn't belong in the PR queue at this stage.
Note that part of the confusion is the recursion is within a process / connection from my understanding - which is where php statics would be used. Mysql locks are our protection against other processes.
On a version of Maria DB > 10.0.2 I can reserve a lock in one process (recursively if I want)
But cannot get it in the other process unless it times out
What moved the other along was an explanation as to how a problem could arise (e.g like #3988 (comment 87911) ). ----------------FROM gitlab
From MariaDB 10.0.2 it is possible to recursively set the same lock. This completely breaks the locking mechanism in CRM_Core_Lock because it assumes that GET_LOCK can only be called once for a named lock.
See: https://mariadb.com/kb/en/get_lock/ "From MariaDB 10.0.2, it is also possible to recursively set the same lock".
This is certainly the case on MariaDB 10.3. But I ran some tests on 10.5 and it doesn't seem to allow you to recursively set the same lock anymore. So I think this goes a long way to explaining why locking doesn't seem to be working properly on some sites.
Before CiviCRM locking mechanism doesn't work on versions of MariaDB (between 10.0.2-10.4.x?) as multiple locks of the same name can be acquired.
After CiviCRM locking mechanism works on mariaDB to limit each lock to a single named lock.
Technical Details Described above.