Skip to content
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

[Lock] MongoDbStore reports a failure to release #37139

Closed
kralos opened this issue Jun 8, 2020 · 2 comments · Fixed by #37140
Closed

[Lock] MongoDbStore reports a failure to release #37139

kralos opened this issue Jun 8, 2020 · 2 comments · Fixed by #37140

Comments

@kralos
Copy link

kralos commented Jun 8, 2020

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/

@kralos kralos added the Bug label Jun 8, 2020
kralos pushed a commit to kralos/symfony that referenced this issue Jun 8, 2020
kralos pushed a commit to kralos/symfony that referenced this issue Jun 8, 2020
@kralos
Copy link
Author

kralos commented Jun 8, 2020

@Baachi I suspect this problem also exists in \Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler::doRead

@xabbuh xabbuh added the Lock label Jun 8, 2020
@Baachi
Copy link
Contributor

Baachi commented Jun 9, 2020

Hey @kralos thanks for reporting this issue.

I think @jmikola would be a better assignee for this issue. I don‘t use mongodb anymore.

kralos pushed a commit to kralos/symfony that referenced this issue Jun 10, 2020
kralos pushed a commit to kralos/symfony that referenced this issue Jun 10, 2020
@fabpot fabpot closed this as completed Jun 10, 2020
fabpot added a commit that referenced this issue Jun 10, 2020
…s (kralos)

This PR was squashed before being merged into the 5.1 branch.

Discussion
----------

[Lock] Fixed reading locks from replica set secondary nodes

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37139
| License       | MIT
| Doc PR        | symfony/symfony-docs#13775

Force lock existence query to use `readPreference=primary` in case the given mongo connection is using any of the following `readPreference`s:

* primaryPreferred
* secondary
* secondaryPreferred
* nearest

Any of the above would fail if a secondary node is queried during a lock release.

Commits
-------

ebf7eaf [Lock] Fixed reading locks from replica set secondary nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants