Skip to content

"There is no active transaction" Error After MySQL Service Restart in FrankenPHP Worker Mode #58039

Closed
@girinabin

Description

@girinabin

Symfony version(s) affected

7.1

Description

I am encountering an issue when running a Symfony application in FrankenPHP worker mode. The problem arises when I restart the MySQL service and then attempt to perform updates that are wrapped in transactions.

How to reproduce

Setup:

  • Use Symfony with Doctrine in a FrankenPHP worker mode environment.
  • Ensure that MySQL is running in a Docker container.

Reproduce the Issue:

  1. Perform an update that is wrapped in a transaction. This operation should complete successfully.
  2. Restart the MySQL service using docker-compose down followed by docker-compose up.
  3. Attempt the same update operation again.

Expected Behavior:

  • The update operation should either complete successfully or, if the connection was lost, Doctrine should handle the reconnection and the transaction should either roll back or restart correctly.

Actual Behavior:

  • For some requests, the operation fails, and the application throws a "MySQL has gone away" error.
  • The error is caught in the catch block, but when attempting to roll back the transaction, another exception is thrown: "There is no active transaction."
  • This issue occurs inconsistently across the different workers in FrankenPHP, making it difficult to handle manually.

Possible Solution

I am already using Symfony 7.1, which includes the fix for idle connections. Additionally, I am using "doctrine/doctrine-bundle": "^2.13.x-dev" (doctrine/DoctrineBundle#1739), and it is already included in my code.

Additional Context

{
    "message": "Beginning transaction",
    "context": {},
    "level": 100,
    "level_name": "DEBUG",
    "channel": "doctrine",
    "datetime": "2024-08-20T14:22:49.896907+05:45",
    "extra": {}
}
{
    "message": "Custom logger message.",
    "context": {
        "message": "SQLSTATE[HY000]: General error: 2006 MySQL server has gone away"
    },
    "level": 400,
    "level_name": "ERROR",
    "channel": "app",
    "datetime": "2024-08-20T14:22:49.897038+05:45",
    "extra": {}
}
{
    "message": "Rolling back transaction",
    "context": {},
    "level": 100,
    "level_name": "DEBUG",
    "channel": "doctrine",
    "datetime": "2024-08-20T14:22:49.897058+05:45",
    "extra": {}
}
{
    "message": "Uncaught PHP Exception Doctrine\\DBAL\\Exception\\DriverException: \"An exception occurred in the driver: There is no active transaction\" at /opt/www/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php line 91",
    "context": {
        "exception": {
            "class": "Doctrine\\DBAL\\Exception\\DriverException",
            "message": "An exception occurred in the driver: There is no active transaction",
            "code": 0,
            "file": "/opt/www/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:91",
            "previous": {
                "class": "Doctrine\\DBAL\\Driver\\PDO\\Exception",
                "message": "There is no active transaction",
                "code": 0,
                "file": "/opt/www/vendor/doctrine/dbal/src/Driver/PDO/Exception.php:28",
                "previous": {
                    "class": "PDOException",
                    "message": "There is no active transaction",
                    "code": 0,
                    "file": "/opt/www/vendor/doctrine/dbal/src/Driver/PDO/Connection.php:123"
                }
            }
        },
        "errors": null
    },
    "level": 500,
    "level_name": "CRITICAL",
    "channel": "app",
    "datetime": "2024-08-20T14:22:49.897387+05:45",
    "extra": {}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions