the Neos website of one of our customers fails at irregular intervals for a few minutes with the error message: “The optimistic lock on an entity failed”.
A self-developed ViewCounter is integrated on the website, which counts up a corresponding integer property of the current document node when called. According to the stack trace, the error occurs as soon as the counter wants to save its changes. (see the following portion of the exception log for reference)
Exception in line 483 of .../Packages/Libraries/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php: The optimistic lock on an entity failed. 41 Doctrine\ORM\OptimisticLockException::lockFailed(Neos\ContentRepository\Domain\Model\NodeData) 40 Doctrine\ORM\Persisters\Entity\BasicEntityPersister::updateTable(Neos\ContentRepository\Domain\Model\NodeData, "neos_contentrepository_domain_model_nodedata", array|2|, TRUE) 39 Doctrine\ORM\Persisters\Entity\BasicEntityPersister::update(Neos\ContentRepository\Domain\Model\NodeData) 38 Doctrine\ORM\UnitOfWork::executeUpdates(Neos\Flow\Persistence\Doctrine\Mapping\ClassMetadata) 37 Doctrine\ORM\UnitOfWork::commit(NULL) 36 Doctrine\ORM\EntityManager::flush() 35 Neos\Flow\Persistence\Doctrine\PersistenceManager_Original::persistAll() 34 Vendor\Site\Fusion\CounterImplementation_Original::evaluate() <- This is the view counter implementation ...
The page counter component was developed by a former colleague, so we can’t ask him about it anymore, but at first sight I was very surprised that
$this->persistenceManager->persistAll() is called manually. Since this call is the origin of the error message, I suspect the problem here, but am not quite sure.
If a NodeData model is changed, the PersistenceManager should recognize this as a data change and automatically trigger the saving process when shutting down the framework, or am I wrong? So could you delete the mentioned line to fix the problem or is there another possible cause?
Apart from that, I am also interested in the actual explanation for the error. Based on the information I have, I don’t quite get what’s wrong here. What exactly does the error message “The optimistic lock on an entity failed” mean? On the web I have only found very vague information, according to which some version does not match between database and application, but that didn’t help me. Besides, I don’t understand why the problem only happens once in a while.
I hope you can help me out in some way and thanks in advance for your participation.
Best regards, Max