-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.5
-
None
-
MOODLE_405_STABLE
It seem the postgres_lock_factory allows multiple of the same lock to be taken out.
For example, if you run this as a unit test, it will fail, because $lock2 will be successfully obtained.
public function test_pg_locks() { |
$factory1 = new \core\lock\postgres_lock_factory('test'); |
$lock1 = $factory1->get_lock('myresource', 0); |
$this->assertNotEmpty($lock1); |
|
$factory2 = new \core\lock\postgres_lock_factory('test'); |
$lock2 = $factory2->get_lock('myresource', 0); |
$this->assertFalse($lock2); |
|
$lock1->release();
|
}
|
To me, if the namespace + resource is the same, the lock should fail to be obtained regardless of the method.
I believe this fails above because of a few preconditions that aren't normally fulfilled:
1. The factory instance being different. This is because the factory does an internal check if it already has the lock (without even going to postgres). Making a new factory instance skips this.
2. The locks being obtained in the same DB session. I'm not super familiar with the internals of pg locks, but I believe if the session is the same postgres will return any advisory locks taken in the same session.
If you change the factory to something else e.g. \core\lock\file_lock_factory, it passes.
My local environment, in case it's relevant:
- Moodle master (currently 2024042200.01)
- PHP 8.1
- Pgbouncer
- Postgres 14
- has a non-specific relationship to
-
MDL-67594 Deprecate supports_recursion() & extend_lock() in the Lock API
- Closed