You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #61091 [Lock] [MongoDB] Enforce readPreference=primary and writeConcern=majority (notrix)
This PR was squashed before being merged into the 6.4 branch.
Discussion
----------
[Lock] [MongoDB] Enforce readPreference=primary and writeConcern=majority
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix#58397
| License | MIT
### The Problem
A scenario was identified, similar to issue #58397, where a lock cannot be successfully released. This occurs when the application:
1. Provides a MongoDB Collection to the `MongoDbStore` with `readPreference` set to `primary`.
2. Has a default `readPreference` of `nearest` configured on the MongoDB manager.
When `release()` is called on a lock, the component first issues a `DELETE` command to the primary MongoDB node. Immediately after, it sends a query to verify the deletion. However, this verification query incorrectly uses the `nearest` read preference from the Doctrine connection, often hitting a secondary node. If replication to the secondary has not yet completed, the verification fails, and an exception is thrown, incorrectly reporting that the lock release failed.
### The Solution
This update enforces `readPreference`=`primary` for and `writeConcern`=`majority`.
This ensures that read and write operations related to the lock are consistently routed, preventing the race condition and ensuring reliable lock releases.
Commits
-------
f0c00db [Lock] [MongoDB] Enforce readPreference=primary and writeConcern=majority
@@ -61,9 +63,9 @@ class MongoDbStore implements PersistingStoreInterface
61
63
privatefloat$initialTtl;
62
64
63
65
/**
64
-
* @param Collection|Client|Manager|string $mongo An instance of a Collection or Client or URI @see https://docs.mongodb.com/manual/reference/connection-string/
65
-
* @param array $options See below
66
-
* @param float $initialTtl The expiration delay of locks in seconds
66
+
* @param Collection|Database|Client|Manager|string $mongo An instance of a Collection or Client or URI @see https://docs.mongodb.com/manual/reference/connection-string/
67
+
* @param array $options See below
68
+
* @param float $initialTtl The expiration delay of locks in seconds
67
69
*
68
70
* @throws InvalidArgumentException If required options are not provided
69
71
* @throws InvalidTtlException When the initial ttl is not valid
@@ -89,8 +91,10 @@ class MongoDbStore implements PersistingStoreInterface
0 commit comments