#7371·dbal

BUG: `beginTransaction()` does not throw `ConnectionLost` after timeout

Author: mhsdesignCreated May 17, 2026Updated Sep 29, 2026

Bug Report

Q A
Version 3.10.5

Summary

In an attempt to get rid of the pattern to ping the connection and reopen i tried to do whats advised with pinging replaced and removed: https://github.com/doctrine/dbal/pull/4119

Instead i attempt to try catch now $this->connection->beginTransaction(); and the actual commit logic with a retry mechanism.

This new pattern would rely on ConnectionLost being thrown.

Current behavior

The ConnectionLost exception is only thrown for executed queries and statements but not for the BEGIN statement if done via beginTransaction()

Doctrine\DBAL\Driver\PDO\PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

doctrine/dbal/src/Driver/PDO/PDOException.php:16
doctrine/dbal/src/Driver/PDO/Connection.php:119
doctrine/dbal/src/Connection.php:1391

Expected behavior

If we ignore the abstraction and use $this->connection->executeStatement('BEGIN'); directly, the exception is correctly converted as expected:

Doctrine\DBAL\Exception\ConnectionLost: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:116
doctrine/dbal/src/Connection.php:1976
doctrine/dbal/src/Connection.php:1918
doctrine/dbal/src/Connection.php:1218

How to reproduce

Use SET SESSION wait_timeout=1 like in the tests here https://github.com/doctrine/dbal/blob/4.2.3/tests/Functional/Connection/ConnectionLostTest.php and open a transaction after waiting 2 seconds. Validate that ConnectionLost is thrown and the connection is closed.