Description
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