Skip to content

Commit 70d0e90

Browse files
committed
BUGFIX: Prevent premature connection to database in PersistenceManager::persistAllowedObjects
For every simple GET request `persistAllowedObjects` is called via the Package.php in flow. This results in building a db connection, even if there is nothing to do. We first check if the `entityManager` is open and if the entity manager has not been used (something is heavily cached via middle-ware or sth) flows objectmanagement retrieves the entity manger. Now in this retrieval process - even though doctrines connection is lazy itself - the connection will be made forcefully see `\Neos\Flow\Persistence\Doctrine\EntityManagerFactory::create` line 120 (https://github.com/neos/flow-development-collection/blob/11e2348125dd8286ff9ccc088e5d187dc9143bf5/Neos.Flow/Classes/Persistence/Doctrine/EntityManagerFactory.php#L120) or https://github.com/neos/flow-development-collection/blob/d93b6b09ca2071c87812a9ef4bc120201c44608a/Neos.Flow/Classes/Persistence/Doctrine/EntityManagerConfiguration.php#L229 This is ironic because if there is no connection - or no entity manager in the first place, the current process cannot have made any changes to the transaction.
1 parent c4d1b64 commit 70d0e90

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Neos.Flow/Classes/Persistence/Doctrine/PersistenceManager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class PersistenceManager extends AbstractPersistenceManager
5353
protected $throwableStorage;
5454

5555
/**
56-
* @Flow\Inject
56+
* @Flow\Inject(lazy=true)
5757
* @var EntityManagerInterface
5858
*/
5959
protected $entityManager;
@@ -117,6 +117,11 @@ public function persistAll(bool $onlyAllowedObjects = false): void
117117
*/
118118
public function persistAllowedObjects(): void
119119
{
120+
if ($this->entityManager instanceof DependencyProxy) {
121+
// the lazy injected entity manger was not instantiated and therefore not used. Nothing is to be committed. Invoking the dependency leads to a db connection request which is obsolete as flow might be shutting down already.
122+
return;
123+
}
124+
120125
if (!$this->entityManager->isOpen()) {
121126
$message = $this->throwableStorage->logThrowable(new PersistenceException('persistAll() skipped flushing data, the Doctrine EntityManager is closed. Check the logs for error messages.', 1643015626));
122127
$this->logger->error($message, LogEnvironment::fromMethodName(__METHOD__));

0 commit comments

Comments
 (0)