Commit 758082a
committed
bug symfony#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 symfony#58397
| License | MIT
### The Problem
A scenario was identified, similar to issue symfony#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=majority1 file changed
+22
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| |||
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
92 | | - | |
93 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
| |||
286 | 290 | | |
287 | 291 | | |
288 | 292 | | |
289 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
290 | 298 | | |
291 | 299 | | |
292 | 300 | | |
| |||
303 | 311 | | |
304 | 312 | | |
305 | 313 | | |
306 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
307 | 317 | | |
308 | 318 | | |
309 | 319 | | |
| |||
345 | 355 | | |
346 | 356 | | |
347 | 357 | | |
348 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
349 | 363 | | |
350 | 364 | | |
351 | 365 | | |
| |||
0 commit comments