Issue Bug Resolved

#109583DatabaseIntegrityCheck->genTree() causes infinite recursion / max_prepared_stmt_count exhaustion on circular page references

Stefan Froemken 04/15/26, 07:20 updated 11/14/26, 21:10

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

  1. Oliver Bartsch commented and changed status Under Review Resolved done 0 % 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.