-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Lock] [MongoDB] Enforce readPreference=primary and writeConcern=majority #61091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It looks like you unchecked the "Allow edits from maintainer" box. That is fine, but please note that if you have multiple commits, you'll need to squash your commits into one before this can be merged. Or, you can check the "Allow edits from maintainers" box and the maintainer can squash for you. Cheers! Carsonbot |
friendly ping @GromNaN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a good idea to use anything other than readPreference=primary
for the lock. Or you could use writeConcern={w:<total number of nodes>}
, but that will cause an error as soon as one mongodb node goes down.
The bug fix is fine, but I believe we should not add the new "readPreference" option, instead we should always use "primary". In that case, we don't really use the replication, .writeConcern
can be always set to w=1
since we are only interested in writing to the primary node
Adding an option is a new feature in Symfony, which can only be merged in the next minor version. But this bugfix need to be done in 6.4
readPreference
I agree, this is not desirable. For something as critical as locking, this should always use a
As @GromNaN already said, we shouldn't rely on anything other than a primary read preference for reads. That guarantees that we're always reading the latest data.
There are a couple of problems I can see with this approach:
With all that in mind, using a |
The PR title and description (and the commit message) should be updated to reflect the new solution being implemented. |
I agree that in order this not to be a new feature we should not introduce new options and only stick to the issue. I have updated fixed readPreference to be |
readPreference
readPreference=primary
and writeConcern=majority
readPreference=primary
and writeConcern=majority
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writeConcern
and readPreference
usage LGTM.
Thank you @notrix. |
…oncern=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
Merged |
The Problem
A scenario was identified, similar to issue #58397, where a lock cannot be successfully released. This occurs when the application:
MongoDbStore
withreadPreference
set toprimary
.readPreference
ofnearest
configured on the MongoDB manager.When
release()
is called on a lock, the component first issues aDELETE
command to the primary MongoDB node. Immediately after, it sends a query to verify the deletion. However, this verification query incorrectly uses thenearest
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 andwriteConcern
=majority
.This ensures that read and write operations related to the lock are consistently routed, preventing the race condition and ensuring reliable lock releases.