Skip to content

Should locking a result for PESSIMISTIC_WRITE refresh the entity cache? #6650

Open
@shauno

Description

@shauno

I'm new to Doctrine and recently ran into an issue in a high(ish) concurrency environment.

In short, when fetching an entity with $query->setLockMode(LockMode::PESSIMISTIC_WRITE);, the result will be overwritten with a cached result if that entity has been fetched earlier in the script (even though the actual query will correctly wait on getting a proper lock, and return the latest correct data).

In researching the issue, I found I can add a ->setHint(Query::HINT_REFRESH, true) to the query which will make sure the entity is not loaded from cache, but should that not be the default behavior when using a LockMode::PESSIMISTIC_WRITE on the query?

I've put together a simple repo illustrating the issue here: https://github.com/shauno/doctrine-stale-demo

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions