Description
Symfony version(s) affected: 5.1.0
Description
When using MongoDbStore
against a replicaSet
with a connection readPreference
other than primary
(the default), the store falsely reports locks don't release. This is because Symfony\Component\Lock\Lock::release()
deletes the key then immediately reads from the store in order to check if the lock was successfully released. The key eviction may not have propagated the replica set at this time and returns exists (true) causing Lock to think the release failed.
How to reproduce
Set up a mongo replicaSet and connect to it from your application with: readPreference=secondary
in your Mongo connection URI. Then try to acquire and release a lock. You should get a: Symfony\Component\Lock\Exception\LockReleasingException
Possible Solution
We should always use readPreference=primary
for all semephore queries (there's only 1: MongoDbStore::exists
).
Additional context
https://docs.mongodb.com/manual/core/read-preference/