#109583DatabaseIntegrityCheck->genTree() causes infinite recursion / max_prepared_stmt_count exhaustion on circular page references
Description
Hello,
In a project with a large number of pages (approx. 20.000), the DatabaseIntegrityCheck->genTree() method enters what appears to be an infinite recursion. This leads to the following Doctrine DBAL error because the maximum number of prepared statements is reached:
Doctrine\DBAL\Exception\DriverException: An exception occurred while executing a query: Can't create more than max_prepared_stmt_count statements (current value: 16382)
The backtrace shows that genTree() calls itself recursively thousands of times (over 10,000 repetitions in the log), even though the actual maximum depth of the page tree is only 8. This suggests that the recursion does not keep track of already visited UIDs or fails to handle circular pid references correctly.
Steps to Reproduce
- Navigate to the “DB-Check” Backend Module.
- Select the “Statistics” submodule.
- If the database contains circular references in the pages table (e.g., a page where uid equals pid or a deeper circular loop), the system will crash with the mentioned DriverException.
Backtrace
(1/3) #1461 Doctrine\DBAL\Exception\DriverException
An exception occurred while executing a query: Can't create more than max_prepared_stmt_count statements (current value: 16382)
in /var/www/html/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php line 102
1252,
1263,
1364,
1566 => new NotNullConstraintViolationException($exception, $query),
default => new DriverException($exception, $query),
};
}
}
at Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter->convert()
in /var/www/html/vendor/doctrine/dbal/src/Connection.php line 1456
Driver\Exception $driverException,
?Query $query,
): DriverException {
$this->exceptionConverter ??= $this->driver->getExceptionConverter();
$exception = $this->exceptionConverter->convert($driverException, $query);
if ($exception instanceof ConnectionLost) {
$this->close();
}
at Doctrine\DBAL\Connection->handleDriverException()
in /var/www/html/vendor/doctrine/dbal/src/Connection.php line 1392
string $sql,
array $params = [],
array $types = [],
): DriverException {
return $this->handleDriverException($e, new Query($sql, $params, $types));
}
/** @internal */
final public function convertException(Driver\Exception $e): DriverException
at Doctrine\DBAL\Connection->convertExceptionDuringQuery()
in /var/www/html/vendor/doctrine/dbal/src/Connection.php line 809
}
return new Result($result, $this);
} catch (Driver\Exception $e) {
throw $this->convertExceptionDuringQuery($e, $sql, $params, $types);
}
}
/**
at Doctrine\DBAL\Connection->executeQuery()
in /var/www/html/vendor/doctrine/dbal/src/Query/QueryBuilder.php line 315
* @throws Exception
*/
public function executeQuery(): Result
{
return $this->connection->executeQuery(
$this->getSQL(),
$this->params,
$this->types,
$this->resultCacheProfile,
at Doctrine\DBAL\Query\QueryBuilder->executeQuery()
in /var/www/html/vendor/typo3/cms-core/Classes/Database/Query/QueryBuilder.php line 250
// Set additional query restrictions
$originalWhereConditions = $this->addAdditionalWhereConditions();
$concreteQueryBuilder = $this->concreteQueryBuilder;
try {
return $concreteQueryBuilder->executeQuery();
} finally {
$concreteQueryBuilder->resetWhere();
if ($originalWhereConditions !== null) {
$concreteQueryBuilder->where($originalWhereConditions);
at TYPO3\CMS\Core\Database\Query\QueryBuilder->executeQuery()
in /var/www/html/vendor/typo3/cms-lowlevel/Classes/Integrity/DatabaseIntegrityCheck.php line 118
$queryBuilder->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($theID, Connection::PARAM_INT))
);
}
$result = $queryBuilder->executeQuery();
// Traverse the records selected
while ($row = $result->fetchAssociative()) {
$newID = $row['uid'];
// Register various data for this item:
at TYPO3\CMS\Lowlevel\Integrity\DatabaseIntegrityCheck->genTree()
in /var/www/html/vendor/typo3/cms-lowlevel/Classes/Integrity/DatabaseIntegrityCheck.php line 144
$this->recStats['doktype'][$row['doktype']] ??= 0;
$this->recStats['doktype'][$row['doktype']]++;
// Add sub pages:
$this->genTree($newID);
// If versions are included in the tree, add those now:
$this->genTree($newID, true);
}
}
at TYPO3\CMS\Lowlevel\Integrity\DatabaseIntegrityCheck->genTree()
in /var/www/html/vendor/typo3/cms-lowlevel/Classes/Integrity/DatabaseIntegrityCheck.php line 146
$this->recStats['doktype'][$row['doktype']]++;
// Add sub pages:
$this->genTree($newID);
// If versions are included in the tree, add those now:
$this->genTree($newID, true);
}
}
/**
at TYPO3\CMS\Lowlevel\Integrity\DatabaseIntegrityCheck->genTree()
in /var/www/html/vendor/typo3/cms-lowlevel/Classes/Integrity/DatabaseIntegrityCheck.php line 146
$this->recStats['doktype'][$row['doktype']]++;
// Add sub pages:
$this->genTree($newID);
// If versions are included in the tree, add those now:
$this->genTree($newID, true);
}
}
/**
at TYPO3\CMS\Lowlevel\Integrity\DatabaseIntegrityCheck->genTree()
in /var/www/html/vendor/typo3/cms-lowlevel/Classes/Integrity/DatabaseIntegrityCheck.php line 146
$this->recStats['doktype'][$row['doktype']]++;
// Add sub pages:
$this->genTree($newID);
// If versions are included in the tree, add those now:
$this->genTree($newID, true);
}
}
/**
at TYPO3\CMS\Lowlevel\Integrity\DatabaseIntegrityCheck->genTree()
in /var/www/html/vendor/typo3/cms-lowlevel/Classes/Integrity/DatabaseIntegrityCheck.php line 146
$this->recStats['doktype'][$row['doktype']]++;
// Add sub pages:
$this->genTree($newID);
// If versions are included in the tree, add those now:
$this->genTree($newID, true);
}
}
/**
at TYPO3\CMS\Lowlevel\Integrity\DatabaseIntegrityCheck->genTree()
in /var/www/html/vendor/typo3/cms-lowlevel/Classes/Integrity/DatabaseIntegrityCheck.php line 146
$this->recStats['doktype'][$row['doktype']]++;
// Add sub pages:
$this->genTree($newID);
// If versions are included in the tree, add those now:
$this->genTree($newID, true);
}
}
/**
at TYPO3\CMS\Lowlevel\Integrity\DatabaseIntegrityCheck->genTree()
…last entry repeats over 10.000 times
Reviews 4
History 211
-
Gerrit Code Review pushed patch set 1 for main to change 96031 status
NewUnder Review <span data-processor="relativetime" data-value="2026-09-24T10:58:06+00:00" > 09/24/26, 10:58 </span> -
Gerrit Code Review pushed patch set 2 for main to change 96031 <span data-processor="relativetime" data-value="2026-09-24T12:12:44+00:00" > 09/24/26, 12:12 </span>
-
Benni Mack changed status
Under ReviewNew <span data-processor="relativetime" data-value="2026-11-11T09:41:49+00:00" > 11/11/26, 09:41 </span> -
Gerrit Code Review pushed patch set 1 for main to change 97537 status
NewUnder Review <span data-processor="relativetime" data-value="2026-11-11T11:24:47+00:00" > 11/11/26, 11:24 </span> -
Gerrit Code Review pushed patch set 2 for main to change 97537 <span data-processor="relativetime" data-value="2026-11-11T12:44:06+00:00" > 11/11/26, 12:44 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 97537 <span data-processor="relativetime" data-value="2026-11-11T14:48:11+00:00" > 11/11/26, 14:48 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 97537 <span data-processor="relativetime" data-value="2026-11-11T15:58:21+00:00" > 11/11/26, 15:58 </span>
-
Gerrit Code Review pushed patch set 1 for main to change 97654 <span data-processor="relativetime" data-value="2026-11-14T16:06:13+00:00" > 11/14/26, 16:06 </span>
-
Gerrit Code Review pushed patch set 1 for 14.3 to change 97666 <span data-processor="relativetime" data-value="2026-11-14T20:44:14+00:00" > 11/14/26, 20:44 </span>
-
Gerrit Code Review pushed patch set 2 for 14.3 to change 97666 <span data-processor="relativetime" data-value="2026-11-14T20:55:59+00:00" > 11/14/26, 20:55 </span>
-
Oliver Bartsch commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-11-14T21:10:12+00:00" > 11/14/26, 21:10 </span>
Applied in changeset commit:8ef5361478a36dccd450579aa051aca747eab47d.