Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql as gone away #290

Closed
PyRowMan opened this issue Nov 2, 2023 · 11 comments
Closed

Mysql as gone away #290

PyRowMan opened this issue Nov 2, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@PyRowMan
Copy link

PyRowMan commented Nov 2, 2023

Hey guys,

I'm using the API-platform way of using frankenphp to create an API managing a MYSQL database,

My issue is that after a long time of inactivity (in dev environment for example) the mysql server closes the connection.

Since the connection seems to stay opened due to frankenphp. I get a "Mysql has gone away" after the wait_timeout as been reached I don't really now how it would be possible to renew the connection automatically. But I think it would be the way here ?

here is my doctrine configuration file if needed :

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'

        # IMPORTANT: You MUST configure your server version,
        # either here or in the DATABASE_URL env var (see .env file)
        #server_version: '15'

        profiling_collect_backtrace: '%kernel.debug%'
    orm:
        auto_generate_proxy_classes: true
        enable_lazy_ghost_objects: true
        report_fields_where_declared: true
        validate_xml_mapping: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

when@test:
    doctrine:
        dbal:
            # "TEST_TOKEN" is typically set by ParaTest
            dbname_suffix: '_test%env(default::TEST_TOKEN)%'

when@prod:
    doctrine:
        orm:
            auto_generate_proxy_classes: false
            proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
            query_cache_driver:
                type: pool
                pool: doctrine.system_cache_pool
            result_cache_driver:
                type: pool
                pool: doctrine.result_cache_pool

    framework:
        cache:
            pools:
                doctrine.result_cache_pool:
                    adapter: cache.app
                doctrine.system_cache_pool:
                    adapter: cache.system

I'm new to frankenphp so I don't understand all the basics of how it works, so if my issue is not where it should be I apologize in advance.

Here is the complete log in case :

{
"channel": "request",
"context":
    {
    "exception":
        {
        "class": "Doctrine\\DBAL\\Exception\\ConnectionLost",
        "code": 2006,
        "file": "/app/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:104",
        "message": "An exception occurred while executing a query: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away",
        "previous":
            {
            "class": "Doctrine\\DBAL\\Driver\\PDO\\Exception",
            "code": 2006,
            "file": "/app/vendor/doctrine/dbal/src/Driver/PDO/Exception.php:28",
            "message": "SQLSTATE[HY000]: General error: 2006 MySQL server has gone away",
            "previous":
                {
                "class": "PDOException",
                "code": 0,
                "file": "/app/vendor/doctrine/dbal/src/Driver/PDO/Statement.php:130",
                "message": "SQLSTATE[HY000]: General error: 2006 MySQL server has gone away"
                }
            }
        }
    },
"datetime": "2023-11-02T19:24:21.790899+01:00",
"extra":
    {
    },
"level": 500,
"level_name": "CRITICAL",
"message": "Uncaught PHP Exception Doctrine\\DBAL\\Exception\\ConnectionLost: \"An exception occurred while executing a query: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away\" at /app/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php line 104"
}
@bpolaszek
Copy link

Related: #233

@dunglas
Copy link
Owner

dunglas commented Apr 25, 2024

Fixed by symfony/symfony#53214.

@dunglas dunglas closed this as completed Apr 25, 2024
@AykutCevik
Copy link

Hello @dunglas, I still face the issue when using Symfony 7.1 and frankenphp:1-php8.3 docker image. After a while, I get the message that the "MySQL server went away". Should it be solved and I might be missing something?

@dunglas
Copy link
Owner

dunglas commented Jul 17, 2024

Be sure to use a version of DoctrineBundle that contains the fix. Last time I checked this was the dev version.

@AykutCevik
Copy link

Thank you, yes, it seems it will be released in 2.13 soon if I'm not mistaken: doctrine/DoctrineBundle@2.12.x...2.13.x

@riskersen
Copy link

riskersen commented Aug 8, 2024

Hi there,

we see the same issue, but with https://packagist.org/packages/doctrine/doctrine-bundle#2.13.x-dev
Normally, the application should either reconnect to the database or send kind of keepalives/ping to the database.
We don't see this behavior on vanilla-php-fpm container..

Any ideas? Perhaps @dunglas ? :)

Short update: as workaround, I increased wait_timeout on mysql side, but that it's quite dirty..

@juslintek
Copy link

Same issue here, but with doctrine-bundle 2.13 stable. :-) Seems like the problem got reintroduced again after the fix. :-)

@riskersen
Copy link

Our workaround is to disable worker mode of frankenphp.. we don't really rely on the speed, so stability and availability is more important to us

@dunglas
Copy link
Owner

dunglas commented Sep 25, 2024

Would you be able to provide a reproducer (a repository with Docker containing minimal code for instance)? I'll take a look.

@juslintek
Copy link

juslintek commented Sep 25, 2024

Hey @dunglas, try api-platform demo, but instead of postgres, make it with mysql: wait_timeout = 10. Also make sure doctrine-bundle is of v2.13. If that does not help to reproduce it, I will create with my own identical packages simple reproducer, but this will take time to prepare.

@juslintek
Copy link

Seems like issue is fixed with php 8.3.11 :-) I was using 8.3.7 it was related to mysql 8.0.36 or percona 8.0.36 pdo bug: php/php-src#13618

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants