Doctrine DBAL throws driver-specific PDO exceptions on server-side statement timeout
0 reputation · 08 May 2020, 06:36 UTC
Goal
The goal is to cancel a long-running Doctrine ORM DQL query and reuse the same Doctrine\DBAL\Connection afterward without driver-specific exception handling.
Constraints
Doctrine DBAL 3.x does not declare a portable cancel() or setTimeout() method on Connection or Statement. PDO timeout attributes such as ATTR_TIMEOUT are driver-dependent and may be silently ignored. Server-side limits like PostgreSQL statement_timeout or MySQL max_execution_time terminate the statement outside Doctrine, after which Doctrine may still attempt to fetch or hydrate and surface a vendor-specific exception from Doctrine\DBAL\Driver\PDO\Exception rather than a Doctrine cancellation exception. Persistent connections can also retain session state after a timeout.
Open questions
- Does Doctrine ORM provide any interception point to stop hydration and close or reset the DBAL connection after the database kills a statement?
- Which combination of Doctrine connection parameters and server session settings is safest for portable timeout behavior across MySQL, PostgreSQL, and SQLite?
- Should application code catch driver-specific PDO exceptions and recreate the EntityManager connection, or is connection reuse safe after a server-side timeout?