Issue Bug Closed

#111010Doctrine messenger transport fails with "MySQL server has gone away" in long-running processes

Benni Mack 10/10/26, 09:59 updated 10/20/26, 15:30

Description

The Doctrine messenger transport gets its own DBAL connection from DoctrineTransportFactory via DriverManager::getConnection(). That connection is not part of the ConnectionPool. It lives as long as the PHP process.

In long-running processes the connection can stay idle longer than the database server allows, for example MySQL’s wait_timeout. The server then closes it. A typical case is scheduler:run executing several tasks in one process: an early task dispatches a message, a later long-running task does not, and a third task dispatches again. The next dispatch() then fails:

An exception occurred in the driver: MySQL server has gone away in vendor/symfony/doctrine-messenger/Transport/DoctrineSender.php:48

Other queries in the same process still work, because they use ConnectionPool connections.

The middlewares added with #110227 do not cover this case. They only act on ConnectionPool connections and only while a worker consumes messages (ConsumedByWorkerStamp). Sending is not covered.

Steps to reproduce
1. Route any message to the doctrine transport.
2. In one CLI process, dispatch a message, wait longer than wait_timeout (or KILL the transport’s connection), then dispatch again.
3. The second dispatch throws “MySQL server has gone away”.

Expected: The transport reconnects and stores the message.
Actual: A TransportException is thrown, the message is lost, and the scheduler task fails.

Proposed fix: When sending fails with Doctrine\DBAL\Exception\ConnectionLost, close the transport’s DBAL connection and retry the send once.

Reviews 1

History 23