propelorm / PropelBundle

PropelBundle for Symfony.
http://propelorm.org/Propel/documentation/#working-with-symfony2
180 stars 156 forks source link

ConnectionWrapper::useDebug = true prevents prepared statements from being closed properly #464

Closed msarris closed 6 years ago

msarris commented 6 years ago

I'm debugging an issue I got with synchronizing with a large dataset via Propel. The error that I got is the following:

SQLSTATE[42000]: Syntax error or access violation: 1461 Can't create more than max_prepared_stmt_count statements (current value: 16382)

I wrote a test script to see if I could isolate the problem, and the following script triggers the issue:

$conn = Propel::getConnection();

$conn->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, false);

$conn->useDebug(true);
//$conn = $conn->getWrappedConnection();

const MAX = 16382;

$i = MAX + 1;
while ($i--) {
    $stmt = $conn->prepare('SELECT * FROM `User` LIMIT 1');
    $stmt->execute();
    $stmt->closeCursor();
}

If you either uncomment the getWrappedConnection line or set useDebug to false, the issue disappears. So it seems somehow useDebug has the effect that ConnectionWrapper doesn't properly close the prepared statements.

Note that prepared statement caching is explicitly turned off, so that is not the problem.

msarris commented 6 years ago

I'll move the issue to the Propel2 repo.